fix: return each node's spans from the distributed trace API - #366
Open
FrameAutomata wants to merge 1 commit into
Open
fix: return each node's spans from the distributed trace API#366FrameAutomata wants to merge 1 commit into
FrameAutomata wants to merge 1 commit into
Conversation
GetDistributedTrace built every node with an empty spans array and never queried the spans table, so the distributed view, the CLI's `traces show` and the MCP get_trace tool all reported zero spans for every service. Spans are stored under their owning endpoint/task/AI-trace id as trace_id, which is what the detail pages read. The handler now collects one (project, entity id, recordedAt) reference per entity node and loads all of them with a single SpanRepository.FindByTraceIds query on every telemetry backend, bounded to the trace window around the earliest and latest node and filtered back to the exact (project, trace) pairs. Exception-only nodes keep an empty list, and the array is never null. The CLI contract seed keyed its span by the OTel trace id, which is the orphan path; it now belongs to the seeded endpoint, so the endpoint-detail and distributed-trace goldens carry the span shape. `traces show` gains a SPANS column, and the dashboard's Distributed Trace card shows a span count per node that expands into that node's waterfall. Closes #352 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #352
Problem
GetDistributedTraceinitialised every node withSpans: []models.Span{}and never queried the spans table. The dashboard's Distributed Trace card,traceway traces show, and the MCPget_tracetool therefore reported zero spans for every service in a trace, even though the response model, the CLI client type and the docs all describe nodes carrying their spans.Fix
Spans are stored under their owning endpoint / task / AI-trace id as
trace_id(the ingest re-roots them), which is exactly what the detail pages read viaSpanRepository.FindByTraceId. The handler now:models.TraceRef{ProjectId, TraceId, RecordedAt}per entity node,SpanRepository.FindByTraceIdsquery, implemented on the SQLite, DuckDB and ClickHouse backends. The query is bounded to the usual ±24h trace window stretched across the earliest and latest node, uses the(project_id, trace_id)index / ordering key, and is filtered back to the exact(project, trace)pairs so the twoINlists' cross product cannot leak a same-id span from a project that did not reference it,spansis nevernull.Spans stored under the OTel trace id itself (the orphan path, when no owner was found in the batch) belong to no node and are still not surfaced, same as today.
Also in this PR
endpoint-detailanddistributed-tracegoldens gain thespans[].*shape lines (regenerated with-update).traceway traces showprints aSPANScolumn.N spanstoggle per node that expands into that node'sSpanWaterfall, reusing the endpoint page's component.Verification
sharedhelper unit tests,TestSpanRepository_FindByTraceIds(+ empty) on SQLite and DuckDB, and a handler testTestGetDistributedTraceAttachesSpansToOwningNodesthat fails onmain(endpoint spans = [], want both owned spans).go buildunder all three tag sets;go testforcontrollers,repositories/telemetry/...,models;cd cli && just test lint gen-skills-check contract-testall green;npm run check/npm run lintclean.checkout-apiSERVER span (two child spans) and anemail-workerCONSUMER span (two child spans) under one trace id, then opened the endpoint page in headless Chromium. The API returned 2 spans on the endpoint node and 2 on the task node, and the card rendered a2 spanstoggle for each that expands into the waterfall with the ingested span names and durations.🤖 Generated with Claude Code