Skip to content

Commit

Permalink
fix(trace): show status of span in trace pannel
Browse files Browse the repository at this point in the history
  • Loading branch information
Defman committed Aug 16, 2024
1 parent e4fce05 commit f0dc99b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ SELECT
Duration / 1000000 AS duration,
Timestamp AS startTime,
arrayMap(key -> map('key', key, 'value', SpanAttributes[key]), mapKeys(SpanAttributes)) AS tags,
arrayMap(key -> map('key', key, 'value', ResourceAttributes[key]), mapKeys(ResourceAttributes)) AS serviceTags
arrayMap(key -> map('key', key, 'value', ResourceAttributes[key]), mapKeys(ResourceAttributes)) AS serviceTags,
if(StatusCode = 'STATUS_CODE_ERROR', 2, 0) AS statusCode
FROM otel.otel_traces
WHERE TraceId = '61d489320c01243966700e172ab37081'
ORDER BY startTime ASC
Expand Down
4 changes: 4 additions & 0 deletions src/dashboards/opentelemetry-clickhouse.json
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,10 @@
{
"hint": "trace_service_tags",
"name": "ResourceAttributes"
},
{
"hint": "trace_status_code",
"name": "StatusCode"
}
],
"database": "default",
Expand Down
8 changes: 6 additions & 2 deletions src/data/sqlGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ describe('SQL Generator', () => {
{ name: 'Duration', type: 'Int64', hint: ColumnHint.TraceDurationTime },
{ name: 'SpanAttributes', type: 'Map(LowCardinality(String), String)', hint: ColumnHint.TraceTags },
{ name: 'ResourceAttributes', type: 'Map(LowCardinality(String), String)', hint: ColumnHint.TraceServiceTags },
{ name: 'StatusCode', type: 'LowCardinality(String)', hint: ColumnHint.TraceStatusCode },
],
filters: [],
meta: {
Expand All @@ -215,7 +216,8 @@ describe('SQL Generator', () => {
'multiply("Duration", 0.000001) as duration,',
`arrayMap(key -> map('key', key, 'value',"SpanAttributes"[key]),`,
`mapKeys("SpanAttributes")) as tags,`,
`arrayMap(key -> map('key', key, 'value',"ResourceAttributes"[key]), mapKeys("ResourceAttributes")) as serviceTags`,
`arrayMap(key -> map('key', key, 'value',"ResourceAttributes"[key]), mapKeys("ResourceAttributes")) as serviceTags,`,
`if("StatusCode" = 'STATUS_CODE_ERROR', 2, 0) as statusCode`,
`FROM "default"."otel_traces" WHERE traceID = 'abcdefg'`,
'LIMIT 1000'
];
Expand All @@ -239,6 +241,7 @@ describe('SQL Generator', () => {
{ name: 'Duration', type: 'Int64', hint: ColumnHint.TraceDurationTime },
{ name: 'SpanAttributes', type: 'Map(LowCardinality(String), String)', hint: ColumnHint.TraceTags },
{ name: 'ResourceAttributes', type: 'Map(LowCardinality(String), String)', hint: ColumnHint.TraceServiceTags },
{ name: 'StatusCode', type: 'LowCardinality(String)', hint: ColumnHint.TraceStatusCode },
],
filters: [],
meta: {
Expand All @@ -260,7 +263,8 @@ describe('SQL Generator', () => {
'multiply("Duration", 0.000001) as duration,',
`arrayMap(key -> map('key', key, 'value',"SpanAttributes"[key]),`,
`mapKeys("SpanAttributes")) as tags,`,
`arrayMap(key -> map('key', key, 'value',"ResourceAttributes"[key]), mapKeys("ResourceAttributes")) as serviceTags`,
`arrayMap(key -> map('key', key, 'value',"ResourceAttributes"[key]), mapKeys("ResourceAttributes")) as serviceTags,`,
`if("StatusCode" = 'STATUS_CODE_ERROR', 2, 0) as statusCode`,
`FROM "default"."otel_traces" WHERE traceID = trace_id AND "Timestamp" >= trace_start AND "Timestamp" <= trace_end`,
'LIMIT 1000'
];
Expand Down
5 changes: 5 additions & 0 deletions src/data/sqlGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ const generateTraceIdQuery = (options: QueryBuilderOptions): string => {
if (traceServiceTags !== undefined) {
selectParts.push(`arrayMap(key -> map('key', key, 'value',${escapeIdentifier(traceServiceTags.name)}[key]), mapKeys(${escapeIdentifier(traceServiceTags.name)})) as serviceTags`);
}

const traceStatusCode = getColumnByHint(options, ColumnHint.TraceStatusCode);
if (traceStatusCode !== undefined) {
selectParts.push(`if(${escapeIdentifier(traceStatusCode.name)} = 'STATUS_CODE_ERROR', 2, 0) as statusCode`);
}
const selectPartsSql = selectParts.join(', ');

// Optimize trace ID filtering for OTel enabled trace lookups
Expand Down
1 change: 1 addition & 0 deletions src/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ export default {
[ColumnHint.TraceDurationTime]: 'Duration Time',
[ColumnHint.TraceTags]: 'Tags',
[ColumnHint.TraceServiceTags]: 'Service Tags',
[ColumnHint.TraceStatusCode]: 'Status Code',
}
}
}
1 change: 1 addition & 0 deletions src/otel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const otel129: OtelVersion = {
[ColumnHint.TraceDurationTime, 'Duration'],
[ColumnHint.TraceTags, 'SpanAttributes'],
[ColumnHint.TraceServiceTags, 'ResourceAttributes'],
[ColumnHint.TraceStatusCode, 'StatusCode'],
]),
traceDurationUnit: TimeUnit.Nanoseconds,
};
Expand Down
1 change: 1 addition & 0 deletions src/types/queryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export enum ColumnHint {
TraceDurationTime = 'trace_duration_time',
TraceTags = 'trace_tags',
TraceServiceTags = 'trace_service_tags',
TraceStatusCode = 'trace_status_code',
}

/**
Expand Down

0 comments on commit f0dc99b

Please sign in to comment.