Skip to content

Commit a87c58e

Browse files
committed
fix(dashboard): only warn on numeric aggregate functions for unknown fields
Functions like count_unique(transaction) and any(span.op) accept non-numeric columns and should not trigger the span-attribute warning. Only numeric aggregates (avg, sum, p50-p100, min, max, percentile) require measurement fields.
1 parent f73a894 commit a87c58e

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

src/commands/dashboard/resolve.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,30 @@ const KNOWN_SPAN_AGGREGATE_FIELDS = new Set([
381381
]);
382382

383383
/**
384-
* Warn when an aggregate argument looks like a span attribute rather than
385-
* an aggregatable field. No-arg functions (count(), epm()) are fine.
384+
* Aggregate functions that require numeric measurement fields.
385+
* Functions like count_unique, any, count accept non-numeric columns
386+
* (e.g., transaction, span.op) and should not trigger the warning.
387+
*/
388+
const NUMERIC_AGGREGATE_FUNCTIONS = new Set([
389+
"avg",
390+
"sum",
391+
"min",
392+
"max",
393+
"p50",
394+
"p75",
395+
"p90",
396+
"p95",
397+
"p99",
398+
"p100",
399+
"percentile",
400+
]);
401+
402+
/**
403+
* Warn when a numeric aggregate function (avg, sum, p50, etc.) is applied
404+
* to a field that isn't a known aggregatable span measurement. Functions
405+
* like count_unique(transaction) or any(span.op) accept non-numeric
406+
* columns and are not checked.
407+
*
386408
* Only checks for the spans dataset.
387409
*/
388410
function warnUnknownAggregateFields(
@@ -397,16 +419,21 @@ function warnUnknownAggregateFields(
397419
if (parenIdx < 0) {
398420
continue;
399421
}
422+
const fn = agg.slice(0, parenIdx);
423+
// Only check numeric aggregate functions — count_unique, any, etc. accept any column
424+
if (!NUMERIC_AGGREGATE_FUNCTIONS.has(fn)) {
425+
continue;
426+
}
400427
const inner = agg.slice(parenIdx + 1, -1);
401-
// No-arg functions like count(), epm() have empty inner — skip
402428
if (!inner) {
403429
continue;
404430
}
405431
if (!KNOWN_SPAN_AGGREGATE_FIELDS.has(inner)) {
406432
log.warn(
407433
`Aggregate field "${inner}" in "${agg}" is not a known aggregatable span field. ` +
408-
"Span attributes (custom tags) cannot be aggregated — use them in --where or --group-by instead. " +
409-
`Known fields: ${[...KNOWN_SPAN_AGGREGATE_FIELDS].join(", ")}`
434+
"Span attributes (custom tags) cannot be used with numeric aggregates — " +
435+
"use them in --where or --group-by instead. " +
436+
`Known numeric fields: ${[...KNOWN_SPAN_AGGREGATE_FIELDS].join(", ")}`
410437
);
411438
}
412439
}

0 commit comments

Comments
 (0)