Skip to content

lib/traceql: support span:* and trace:* Tempo intrinsic filters - #333

Closed
aloneangel45 wants to merge 2 commits into
VictoriaMetrics:masterfrom
aloneangel45:fix/traceql-tempo-intrinsics
Closed

aloneangel45 wants to merge 2 commits into
VictoriaMetrics:masterfrom
aloneangel45:fix/traceql-tempo-intrinsics

Conversation

@aloneangel45

Copy link
Copy Markdown

Describe Your Changes

Supports Tempo TraceQL intrinsic filters that previously produced unmapped field names and returned empty trace sets:

  • Span intrinsics (TraceQLFieldToVTField in lib/traceql/filter_general.go):
    • Mapped span:name -> name, span:status -> status_code (preserving ok/error/unset enum rewrites), span:kind -> kind (preserving enum rewrites), span:duration -> duration, span:id -> span_id, span:parentID -> parent_span_id, and span:statusMessage / statusMessage -> status_message.
    • Updated app/vtselect/traces/tempo/metrics_query.go so aggregations over span:duration also scale nanoseconds to seconds like duration.
  • Trace duration (trace:duration):
    • Shared isTraceDurationField between filterCommon.String() and GetTraceDurationFilters() so { trace:duration ... } uses the trace_id_idx_stream join identically to { traceDuration ... }.
  • Trace root intrinsics (trace:rootService, rootServiceName, rootName, trace:rootName):
    • Resolved trace-root predicates against the trace's root span (parent_span_id:="") via trace_id:in({resource_attr:service.name!=""} AND parent_span_id:="" AND <root-predicate> | fields trace_id), enabling both standalone root queries and cross-span conjunctions/disjunctions (e.g. matching a child span whose trace has a given root service).
  • Tests:
    • Added translation, LogsQL parser, metrics by(...) / avg_over_time(span:duration), and real in-process logstorage.Storage integration tests (TestTempoIntrinsicFilters, TestTempoIntrinsicFiltersAgainstStorage) in lib/traceql/parser_test.go, lib/traceql/pipe_metrics_test.go, and app/vtselect/traces/tempo/metrics_query_test.go.

Closes #325

Checklist

  • Verified locally with go vet ./lib/traceql/... ./app/vtselect/... and go test -count=1 -race ./lib/traceql/... ./app/vtselect/...

@cubic-dev-ai cubic-dev-ai Bot left a comment •

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.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread lib/traceql/parser_test.go Resolved
Comment thread lib/traceql/filter_general.go Resolved
Comment thread lib/traceql/pipe_metrics_test.go Resolved
@aloneangel45

Copy link
Copy Markdown
Author

Thanks for the review! Addressed all four cubic-dev-ai findings in the latest commit:

  1. Preserve OR scoping for trace:duration / traceDuration (lib/traceql/filter_general.go, lib/traceql/filter_or.go): When a trace:duration / traceDuration predicate appears inside an OR branch, it now renders inline via trace_id:in({trace_id_idx_stream!=""} AND duration:<op><ns> | fields trace_id_idx) instead of being hoisted to a global trailing | join, preserving boolean OR/AND semantics while keeping top-level/AND join syntax unchanged.
  2. Checked RunQuery error (lib/traceql/parser_test.go): Added storage.RunQuery(...) error checking and real logstorage.Storage test cases covering OR with trace:duration.
  3. Asserted scaleDurationToSeconds (app/vtselect/traces/tempo/metrics_query_test.go): Explicitly verified tr.scaleDurationToSeconds is true for avg_over_time(span:duration).
  4. Tested unprefixed statusMessage (lib/traceql/pipe_metrics_test.go): Added statusMessage -> status_message mapping assertion.

Re-ran go vet ./lib/traceql/... ./app/vtselect/... and go test -count=1 -race ./lib/traceql/... ./app/vtselect/... (all 6 packages passed).

@f41gh7 f41gh7 closed this Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tempo API: span:name, trace:duration and rootServiceName find no traces

2 participants