Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/error-span-predicate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/app': patch
---

Count spans recorded with the legacy `STATUS_CODE_ERROR` status as errors on the Services and LLM dashboards. The errored-span definition now lives in one place and matches both that value and the short `Error` form, so those dashboards no longer undercount errors from collectors that emit the long form.
2 changes: 1 addition & 1 deletion packages/app/src/__tests__/serviceDashboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ describe('Service Dashboard', () => {

expect(result.current.isLoading).toBe(false);
expect(result.current.expressions?.isError).toBe(
"lower(StatusCode) = 'error'",
"lower(StatusCode) IN ('error', 'status_code_error')",
);
expect(result.current.expressions?.isSpanKindServer).toContain(
'SpanKind IN',
Expand Down
8 changes: 6 additions & 2 deletions packages/app/src/llm/__tests__/expressions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ describe('getLLMExpressions', () => {
expect(expressions.isLLMSpan).toContain(
"mapContains(SpanAttributes, 'gen_ai.operation.name')",
);
expect(expressions.isError).toBe("lower(StatusCode) = 'error'");
expect(expressions.isError).toBe(
"lower(StatusCode) IN ('error', 'status_code_error')",
);
expect(expressions.durationInMillis).toBe('Duration/1e6');
// Provided cost takes precedence in the cost expression.
expect(expressions.costUsd.startsWith('if((greatest(')).toBe(true);
Expand Down Expand Up @@ -274,7 +276,9 @@ describe('getLLMExpressions', () => {
[],
);
expect(expressions.model).toContain("Attrs['gen_ai.response.model']");
expect(expressions.isError).toBe("lower(Status) = 'error'");
expect(expressions.isError).toBe(
"lower(Status) IN ('error', 'status_code_error')",
);
expect(expressions.durationInMillis).toBe('DurationNs/1e6');
});
});
Expand Down
12 changes: 10 additions & 2 deletions packages/app/src/llm/lib/expressions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { TLogSource, TTraceSource } from '@hyperdx/common-utils/dist/types';

import { errorStatusPredicateSql } from '@/source';

import { generateCostSqlExpression } from './cost';
import { buildAnyKeyExistsSql, buildLLMSpanSqlPredicate } from './detect';

Expand Down Expand Up @@ -452,7 +454,7 @@ export function getLLMExpressions(source: TTraceSource, jsonColumns: string[]) {
...attributeExpressions,
...fieldExpressions,
...auxExpressions,
isError: `lower(${fieldExpressions.severityText}) = 'error'`,
isError: errorStatusPredicateSql(fieldExpressions.severityText),
hasTokens: `${attributeExpressions.totalTokens} > 0`,
};
}
Expand Down Expand Up @@ -481,7 +483,13 @@ export function getLLMLogExpressions(
...attributeExpressions,
service: source.serviceNameExpression || 'ServiceName',
severityText,
/** Error log events (mirrors the serviceDashboard convention). */
/**
* Error log events. Severity text has its own vocabulary, so this keeps a
* predicate of its own rather than reusing the span-status one: the extra
* status value that predicate matches cannot appear in a severity-text
* column, and the values severity text does use for errors are a
* different set.
*/
isError: `lower(${severityText}) = 'error'`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 minor — New comment says severity text uses a different set of error values, but the predicate still matches only 'error'

The new comment (and the one on errorStatusPredicateSql in source.ts) says severity-text errors are a different set ('fatal', 'crit' and so on). The code right below it is still lower(severityText) = 'error', so fatal and critical log events are left out of the LLM log error count. Either widen the predicate to the values the comment lists, or reword the comment so it only explains why the span-status helper isn't reused here.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

/**
* Log events that belong to LLM activity: explicit LLM markers or any
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/serviceDashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { escapeSqlString } from '@hyperdx/common-utils/dist/core/utils';
import { SourceKind, TTraceSource } from '@hyperdx/common-utils/dist/types';

import { useColumns, useJsonColumns } from './hooks/useMetadata';
import { errorStatusPredicateSql } from './source';

const COALESCE_FIELDS_LIMIT = 100;

Expand Down Expand Up @@ -225,7 +226,7 @@ export function getExpressions(

const filterExpressions = {
isEndpointNonEmpty: `NOT empty(${auxExpressions.endpoint})`,
isError: `lower(${fieldExpressions.severityText}) = 'error'`,
isError: errorStatusPredicateSql(fieldExpressions.severityText),
isSpanKindServer: `${fieldExpressions.spanKind} IN ('Server', 'SPAN_KIND_SERVER')`,
isDbSpan: `${fieldExpressions.dbStatement} <> ''`,
};
Expand Down
14 changes: 14 additions & 0 deletions packages/app/src/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,20 @@ export function getDurationSecondsExpression(source: TTraceSource) {
return `(${source.durationExpression})/1e${source.durationPrecision ?? 9}`;
}

/**
* The single definition of an errored span, as a SQL predicate over a span
* status-code expression. Matches both the short OTel status ('Error'/'ERROR')
* and the legacy collector form ('STATUS_CODE_ERROR'), which some collectors
* write instead.
*
* Span status only. Log severity text is a different vocabulary (its error
* values are 'fatal', 'crit' and friends, never 'status_code_error'), so log
* callers keep their own predicate rather than reusing this one.
*/
export function errorStatusPredicateSql(statusCodeExpression: string): string {
return `lower(${statusCodeExpression}) IN ('error', 'status_code_error')`;
}

// Aggregate functions whose output preserves the unit of the input value.
// count and count_distinct produce dimensionless counts and should not
// inherit the duration format.
Expand Down
Loading