Skip to content

Commit

Permalink
Fix trace_start and trace_end changes from #890 (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerTorres authored Jul 11, 2024
1 parent 13014f7 commit 1e96c97
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Fix trace start times in trace ID mode (#900)

## 4.3.0

### Features
Expand Down
4 changes: 2 additions & 2 deletions src/data/sqlGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('SQL Generator', () => {
`arrayMap(key -> map('key', key, 'value',"SpanAttributes"[key]),`,
`mapKeys("SpanAttributes")) as tags,`,
`arrayMap(key -> map('key', key, 'value',"ResourceAttributes"[key]), mapKeys("ResourceAttributes")) as serviceTags`,
`FROM "default"."otel_traces" WHERE traceID = trace_id AND startTime >= trace_start AND startTime <= trace_end`,
`FROM "default"."otel_traces" WHERE traceID = trace_id AND "Timestamp" >= trace_start AND "Timestamp" <= trace_end`,
'LIMIT 1000'
];

Expand Down Expand Up @@ -335,7 +335,7 @@ describe('SQL Generator', () => {
};
const expectedSqlParts = [
'SELECT "TraceId" as traceID, "ServiceName" as serviceName, "SpanName" as operationName,',
'multiply(toUnixTimestamp64Nano("Timestamp"), 0.000001) as startTime, multiply("Duration", 0.000001) as duration',
'"Timestamp" as startTime, multiply("Duration", 0.000001) as duration',
'FROM "default"."otel_traces" WHERE ( Timestamp >= $__fromTime AND Timestamp <= $__toTime )',
'AND ( ParentSpanId = \'\' ) AND ( Duration > 0 ) ORDER BY Timestamp DESC, Duration DESC LIMIT 1000'
];
Expand Down
8 changes: 4 additions & 4 deletions src/data/sqlGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const generateTraceSearchQuery = (options: QueryBuilderOptions): string => {

const traceStartTime = getColumnByHint(options, ColumnHint.Time);
if (traceStartTime !== undefined) {
selectParts.push(`${convertTimeFieldToMilliseconds(escapeIdentifier(traceStartTime.name))} as startTime`);
selectParts.push(`${escapeIdentifier(traceStartTime.name)} as startTime`);
}

const traceDurationTime = getColumnByHint(options, ColumnHint.TraceDurationTime);
Expand Down Expand Up @@ -149,7 +149,7 @@ const generateTraceIdQuery = (options: QueryBuilderOptions): string => {
// Optimize trace ID filtering for OTel enabled trace lookups
const hasTraceIdFilter = options.meta?.isTraceIdMode && options.meta?.traceId;
const otelVersion = otel.getVersion(options.meta?.otelVersion);
const applyTraceIdOptimization = hasTraceIdFilter && options.meta?.otelEnabled && otelVersion;
const applyTraceIdOptimization = hasTraceIdFilter && traceStartTime !== undefined && options.meta?.otelEnabled && otelVersion;
if (applyTraceIdOptimization) {
const traceId = options.meta!.traceId;
const timestampTable = getTableIdentifier(database, table + otel.traceTimestampTableSuffix);
Expand All @@ -173,9 +173,9 @@ const generateTraceIdQuery = (options: QueryBuilderOptions): string => {
if (applyTraceIdOptimization) {
queryParts.push('traceID = trace_id');
queryParts.push('AND');
queryParts.push(`startTime >= trace_start`);
queryParts.push(`${escapeIdentifier(traceStartTime.name)} >= trace_start`);
queryParts.push('AND');
queryParts.push(`startTime <= trace_end`);
queryParts.push(`${escapeIdentifier(traceStartTime.name)} <= trace_end`);
} else if (hasTraceIdFilter) {
const traceId = options.meta!.traceId;
queryParts.push(`traceID = '${traceId}'`);
Expand Down

0 comments on commit 1e96c97

Please sign in to comment.