Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trace_start and trace_end changes from #890 #904

Merged
merged 4 commits into from
Jul 11, 2024
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
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
Loading