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

Closed
AL
3d ago
+178-19

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