app/vtselect/traces/tempo: return matched spans in /api/search instead of root span#174
Open
yusufcemalcelebi wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
1 issue found across 14 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
f1f0a39 to
15f5e98
Compare
spanSets[].spans[] now contains the spans that satisfied the TraceQL filter (real spanID, name and query-referenced attributes), so Grafana deep-links to the matched span instead of the trace root. matched reports the true count regardless of root-span presence, and serviceStats is included. Matched spans are detected within the existing all-spans scan via a 'format if (<filter>) "1" as _vt_matched' pipe, so no extra storage query is needed. Signed-off-by: yusufcemalcelebi <yusuf@mailerlite.com>
15f5e98 to
548e5f0
Compare
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.
Problem
The Tempo-compatible
/select/tempo/api/searchendpoint populatedspanSets[].spans[]with the trace root span (carrying a synthesizednestedSetParent=-1and onlyservice.name) instead of the spans that actually satisfied the TraceQL filter.Grafana's Tempo datasource deep-links to
spanSets[].spans[].spanID, so clicking a result row always focused the root span rather than the matched child span (real Tempo focuses the matched span).matchedwas also coupled to root-span presence, returning0when the root had not yet been ingested even though child spans matched.Fix
Retain the spans that matched the filter and project them into the response:
| format if (<filter>) "1" as _vt_matchedpipe — no extra storage query/round-trip. Non-matching spans are still returned (carrying no marker), since trace-level metadata (duration, per-service stats) is derived from all spans of the trace.matchedSpanswith their realspanID,name, start/duration and the query-referenced attributes (mirroring Tempo —kind/statusrendered as names, scope prefixes stripped;nameemitted only when referenced).matchedreports the true count regardless of root presence, capped byspss. Root span is used only for trace-level metadata.Query.ReferencedFields()andKindCodeToNamefor the projection.serviceStatsblock (per-service span/error counts) and drop the synthesized root span /nestedSetParent=-1.spss(spansPerSpanSet) query param (default 3, clamped to [1, 1000]).Out of scope (follow-ups): accepting
kindenum names likekind=consumeron input, and the top-level metrics block.Testing
tempo_test.go): decisive case (root present but non-matching -> matched child returned, not root; the unmarked root is not counted) and the root-absent case (count still correct)./api/searchcalls):q={ span.http.status_code = "500" }-> returns the childspanIDwith only the query-referenced attribute (http.status_code: "500"),matched: 1, nonestedSetParent, trace metadata from the root, and a populatedserviceStats(service-b->errorCount: 1).q={}-> both spans marked,matched: 2.make fmt,make vet,go build ./..., andtempo+traceqlpackage tests pass.