Skip to content

fix(api): trace list — label by root span; service filter keeps whole trace - #274

Open
vmax wants to merge 2 commits into
thejefflarson:mainfrom
vmax:fix/trace-list-root-and-service-filter
Open

vmax wants to merge 2 commits into
thejefflarson:mainfrom
vmax:fix/trace-list-root-and-service-filter

Conversation

@vmax

@vmax vmax commented Nov 15, 2026

Copy link
Copy Markdown

Closes #272. Closes #273.

Two independent bugs in query_traces, one commit each (they touch adjacent lines of the same SQL, so separate PRs would just conflict). Repro trace + script: #272 (comment)

1. Label each trace by its root span (#272)

max(service) picked the alphabetically-last service in the trace, and root_name was the earliest span. Both now come from the parentless span, falling back to the earliest span for a partial trace:

(array_agg(service ORDER BY (parent_span_id IS NULL) DESC, start_time))[1] AS service,
(array_agg(name    ORDER BY (parent_span_id IS NULL) DESC, start_time))[1] AS root_name,

The name (root span) filter in HAVING uses the same expression.

2. Service filter keeps the whole trace (#273)

WHERE service = $1 dropped the other services' spans before GROUP BY, so root/duration/span count/error count described a fragment. It's now a trace_id IN (SELECT … WHERE service = $1 AND <same window>) subquery — same shape as the existing attr filter — and the aggregates run over the whole trace, as the comment above the query already promised.

The subquery is served by spans_service_start_idx:

SubPlan 1
  ->  Bitmap Heap Scan on spans spans_1
        Recheck Cond: ((service = 'svc3') AND (start_time >= (now() - '24:00:00')))
        ->  Bitmap Index Scan on spans_service_start_idx

Tests

  • trace_list_labels_trace_by_its_root_span — 3-service trace with the root in the alphabetically-first service and a clock-skewed leaf span that starts before the root; partial trace with no root → earliest span; name filter matches the root. On main: left: "demo-c-pay", right: "demo-a-gateway".
  • trace_list_service_filter_keeps_whole_trace — focusing either end of the chain returns the identical whole-trace row; errors_only + gateway focus finds the downstream error; unrelated service still excluded. On main: demo-a-gateway: span_count left: 2, right: 4.
  • cargo fmt --check, cargo clippy --all-targets -D warnings, cargo test (same unrelated local-only rollup_vacuum_health_canary_… caveat as feat(logs): filter by minimum severity #269/fix(api): attribute filter matches typed (number/bool) values #271).

🤖 Generated with Claude Code

vmax and others added 2 commits November 15, 2026 23:23
The trace list took `max(service)` (alphabetically last service in the
trace) as the trace's service and the earliest span's name as its root,
so multi-service traces were attributed to whichever service sorts last,
and clock skew between hosts could pick a non-root span as "root".

Order by "is parentless" first, then start time, for both service and
root_name (and the root-name filter), falling back to the earliest span
when the root hasn't arrived.

Closes thejefflarson#272

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`?service=X` filtered spans before GROUP BY, so root name, duration,
span count and error count were computed over X's spans only: focusing
the gateway hid downstream errors from `errors_only`, focusing a leaf
service showed its own span as the "root" with its own duration.

Select traces that contain a span of X via a subquery (served by
spans_service_start_idx), like the attribute filter already does, and
keep aggregating over all of the trace's spans.

Closes thejefflarson#273

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Trace list service filter truncates traces to that service's spans Trace list labels traces with the alphabetically-last service, not the root span's

1 participant