Skip to content

lib/traceql: intersect traces by trace_id for && between spansets - #330

Closed
aloneangel45 wants to merge 2 commits into
VictoriaMetrics:masterfrom
aloneangel45:fix/traceql-spanset-and
Closed

aloneangel45 wants to merge 2 commits into
VictoriaMetrics:masterfrom
aloneangel45:fix/traceql-spanset-and

Conversation

@aloneangel45

Copy link
Copy Markdown

Fixes #324

Root Cause

parseFilterAnd previously emitted the same single-row a and b LogsQL expression both inside {...} (same-span conjunction) and between spansets {...} && {...}. For queries like { span.a = "x" } && { span.b = "y" }, LogsQL required a single span to carry both attributes, returning no traces when a and b sit on different spans of the same trace.

Fix

  • Track inSpan context in lib/traceql/parser.go so && inside {...} stays a single-span and filter, while && between spansets is marked isSpanset: true.
  • In lib/traceql/filter_and.go, spansetString() skips wildcard (*) operands and translates multi-spanset intersections to ((s0) or (s1) ...) and trace_id:in({resource_attr:service.name!=""} AND (s0) | uniq by (trace_id)) and ... so matching traces return all spans matching any operand while requiring every operand to match at least one span in the trace.
  • Updated TestParseQuery expectations and added TestSpansetAndQueryExecution against logstorage.Storage covering parent/child spanset &&, 3-way &&, nested &&/||, stream-field spansets, and step-2 FilterString() retrieval.

Testing

  • go test -v ./lib/traceql/... — PASS
  • go test ./lib/... ./app/... — PASS
  • go vet ./lib/traceql/... — PASS

@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.

No issues found across 3 files

Re-trigger cubic

@aloneangel45

Copy link
Copy Markdown
Author

Merged upstream/master in 118728d and updated the lib/traceql/parser_test.go expectations to include the OR-filter parentheses introduced in #320. Verified go test ./lib/traceql/... ./app/vtselect/... passes locally.

…et-and

# Conflicts:
#	lib/traceql/parser_test.go
@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: && between two spansets returns no traces

2 participants