Logs: Only query Tempo with a validated trace ID in log line details #876
All Vouch review confidence checks passed
Residual risk 0.29 = Change Risk (0.55) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.55 · 603 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.383
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #876"
general
weight: 0.35
cursor[bot]
<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
What is this feature?
A fix for the Trace section in log line details. That section now sends a Tempo lookup only when the Tempo data link's query is a bare hex trace ID (
abcd1234) or an exact trace-id lookup ({ trace:id = "abcd1234" }). It sends only that hex ID. For any other link query it shows the existing "Could not retrieve trace." message and does not call the datasource.Why do we need this feature?
LogLineDetailsTraceusedgetTraceIdFromTraceQlQuery(traceRef.query) ?? traceRef.query. When no trace ID could be extracted, it sent the whole interpolated link query to the linked Tempo datasource withqueryType: 'traceql'. Data links and correlations put log field values into that query without escaping. So anyone who can write a log line could choose the TraceQL that runs under the viewer's Tempo credentials when the viewer expanded the Trace section, or when it reopened on its own from local storage.The change:
links.tsaddsgetTraceIdFromLinkQuery. It returns a trimmed hex ID only when the whole query is a bare hex ID or an exact{ trace:id = "<hex>" }lookup. It returnsundefinedfor anything else, including values that are not strings.LogLineDetailsTrace.tsxcomputes the trace ID once from the link query, and that ID is the only value used to build the request. If there is no ID, it sets the unavailable state and returns before querying. The raw link query never reachesdataSource.query.Who is this feature for?
Anyone who views logs that have Tempo data links or correlations.
Which issue(s) does this PR fix?:
The tests in https://github.com/shaw-andy/grafana/pull/874 prove this fix. They are left out of this PR.
Special notes for your reviewer:
Tests run:
yarn jest --watchAll=false public/app/features/logs/components/panel/LogLineDetails.test.tsx -t "TraceQL link injection"):- Unchanged code: 5 failed, 1 passed. Each failure shows the attacker's selector sent to Tempo as TraceQL.
- With this fix: 6 passed.
yarn jest --watchAll=false public/app/features/logs/components/panel/:- On the #874 branch with the fix applied: 20 suites, 476 tests passed.
- On this branch: 20 suites, 470 tests passed.
getTraceIdFromLinkQuerycases inlinks.test.tstry the same technique in other forms. They cover a bare ID followed by a newline and a selector,||breakouts,{ true },0xprefixes, an empty string, and inputs that are not strings. All are rejected. Bare hex IDs and exact lookups are still accepted.eslint,prettier --checkandtsc --noEmitpass for the changed files.Other call sites I checked: this is the only frontend code that runs a log-derived link query against Tempo automatically.
explore/TraceView/.../SpanDetail/LogsLink.tsx(useHasLogs) also runs a link query automatically, but in the other direction. It probes for logs using Loki queries that the trace-to-logs settings build from span tags, behind the dynamic trace-to-logs flag. That is a different operation, and this PR does not change it.Please check that:
<!-- CURSOR_AGENT_PR_BODY_END -->
<div><a href="https://cursor.com/agents/bc-5f7dd46a-00d7-4845-90b8-d292bdba38ae?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a> <a href="https://cursor.com/background-agent?bcId=bc-5f7dd46a-00d7-4845-90b8-d292bdba38ae&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a> </div>
<!-- CURSOR_SUMMARY -->
---
<!-- /CURSOR_SUMMARY -->