Skip to content

[Feature Request] Trace-level AND search across spans #3004

Open

Description

@milansanjeev

Summary

The search bar evaluates AND at the span/row level. There is no way to express a trace-level filter: return traces where property A appears on some span and property B appears on a (possibly different) span in the same trace.

That is a common query when correlation IDs are stamped once at the edge and service name (or other attributes) live on downstream spans.

Problem

A query like:

SpanAttributes.tuid:"abc123" AND ServiceName:checkout-service

Expected (Jaeger / Haystack / many APM UIs): traces that contain both predicates, even if they sit on different spans.

Actual: 0 results unless a single span has both fields.

This is easy to misread as a bug. The search bar is doing what it was built to do — filtering rows. The gap is that trace-level, cross-span AND is not expressible there.

Why this happens

Typical OpenTelemetry instrumentation stamps a correlation ID (request ID, tenant ID, user ID, etc.) on the gateway/entry span. Downstream services appear as separate spans in the same trace and often do not copy that ID onto every child.

So a real trace can look like:

Span ServiceName tuid
entry gateway-service abc123
child checkout-service (unset)
  • Trace-level AND matches this trace
  • Span-level AND matches nothing

Current workaround

Intersect two TraceId sets outside the where bar:

  1. TraceIds where any span has tuid = X
  2. TraceIds where any span has ServiceName = Y
  3. Fetch full traces for the intersection

That works against ClickHouse, but it is not something a user can do from the search bar.

Proposed behavior

Support a trace-scoped search mode (or syntax) where boolean operators apply at the trace:

  • A AND B → traces that contain a span matching A and a span matching B
  • Keep today’s span-level AND as an explicit mode, since it is still useful (“this span is slow and this span is checkout-service”)

Jaeger, Haystack, and several commercial APM products default to the trace-level interpretation for this class of query.

Additional context

Verified directly in ClickHouse on otel_traces-style data: the traces exist; no single row satisfies both predicates. Happy to share a minimal SQL sketch of the TraceId intersection if useful.

Activity

  1. milansanjeev commented on Sep 3, 2026

    @milansanjeev
    ContributorAuthor

    Proposed approach: trace-scoped filter matching, built on the existing filters array

    Dug into the query pipeline to scope this. Summary of where things stand and a concrete, contained proposal for an MVP.

    Today: a Lucene/SQL where string is parsed once and flattened into a single boolean SQL expression evaluated per-row (packages/common-utils/src/queryParser.ts's serialize()) -- there's no per-clause independence there. But the search page already has a parallel, more structured mechanism: the filters array + filtersLogicalOperator (packages/app/src/DBSearchPage.tsx), where each Filter is rendered independently (renderWhereExpression) and then joined by AND/OR (renderChartConfig.ts's renderWhere(), ~line 1459). That's a much better foundation for this feature than the raw where-bar text, because each filter chip is already a self-contained, independently-renderable condition.

    Proposed MVP: a "Match across trace" toggle (only surfaced/meaningful for Trace-kind sources), scoped to the filters array:

    • When off (today's behavior): filters combine into one WHERE clause, evaluated per-row.
    • When on: each filter's own rendered condition gets wrapped as
      TraceId IN (
        SELECT DISTINCT <traceIdExpression>
        FROM <source table>
        WHERE <same time range>
          AND <that filter's rendered condition>
      )
      and these IN (...) conditions are ANDed together in the outer query -- so tuid:"abc123" AND ServiceName:checkout-service becomes "trace contains a span matching tuid, and a span matching ServiceName", not "one span matches both".

    This isn't new SQL shape for the codebase: renderChartConfig.ts already builds tuple(...) IN (SELECT \group` FROM ...)CTEs for series/group limiting (~lines 1619, 2190), and every trace-kind source already has a resolvabletraceIdExpression (packages/common-utils/src/types.ts:2261) to use as the correlation key. The rendering change would live alongside renderWhere()`, not inside the Lucene parser.

    Deliberately out of scope for the MVP: the raw where-bar text's top-level AND (the issue's literal example syntax). Filter chips already give trace-scoping a clean per-clause boundary; the where-bar string doesn't -- telling a straight A AND B chain apart from A AND (B OR C) or a negated clause, and deciding what "trace-scoped" even means for OR/NOT, is real design work I'd rather not conflate with getting the mechanism landed. Could be a fast follow if the filter-chip version proves out.

    Questions before I put together a PR:

    • Toggle placement/naming -- next to filtersLogicalOperator's AND/OR control, or a separate "search mode" concept?
    • Should this only appear for Trace sources, or also Log sources correlated via a trace ID column?
    • Any existing internal discussion/design constraints I should know about before building on the filters plumbing this way?

    Happy to draft the PR once there's rough agreement on the above.

  2. brandon-pereira commented on Sep 18, 2026

    @brandon-pereira
    Member

    @MikeShi42 @alex-fedotyev have you heard from others if this is requested by customers?

    Also curious from OSS - if you think this would be helpful, please thumbs up the issue/this comment. Thanks!

  3. added
    Needs Feedback
    on Oct 9, 2026
  4. pulpdrew commented on Dec 4, 2026

    @pulpdrew
    Contributor

    Just to echo some comments on #3154 - this is something we're looking to support in the future, using relational fields like any.SpanName:GET AND root.Duration:>1000. It's also desirable in chart contexts to support grouping by these relational fields, which lends support to a self-join implementation rather than an TraceId IN (subquery) implementation.

    One current concern is performance on large data sets - TraceId IN (subquery)` and self-joins can be somewhat expensive when the condition matches large numbers of trace ids, so we may look at core database level improvements to make this performant.

    A current workaround is to manually specify a TraceId IN (subquery) pattern as a SQL WHERE condition on the search page or chart definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs Feedbackexternalfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions