fix(telemetry): show last attempted key labels for failed requests#3042
fix(telemetry): show last attempted key labels for failed requests#3042loss-and-quick wants to merge 1 commit intomaximhq:mainfrom
Conversation
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Confidence Score: 5/5Safe to merge — single-file change with correct fallback logic and no risk of data loss or incorrect label overwriting on success paths. The only finding is a P2 suggestion about adding unit tests; no logic errors, security issues, or correctness problems were identified. The fallback condition is gated on No files require special attention. Important Files Changed
Reviews (1): Last reviewed commit: "fix(telemetry): show last attempted key ..." | Re-trigger Greptile |
| if selectedKeyID == "" && len(attemptTrail) > 0 { | ||
| last := attemptTrail[len(attemptTrail)-1] | ||
| selectedKeyID = last.KeyID | ||
| selectedKeyName = last.KeyName | ||
| } |
There was a problem hiding this comment.
No unit tests for the fallback path
The PR description references go test ./... in plugins/telemetry, but there are no *_test.go files in that directory. The fallback logic (lines 405–409) is straightforward, but a table-driven test covering (a) failed request with non-empty attemptTrail, (b) failed request with empty attemptTrail, and (c) successful request where selectedKeyID is already set would make the invariant explicit and catch regressions if KeyAttemptRecord changes shape in the future.
Summary
When an LLM request fails,
core/bifrost.gointentionally clearsBifrostContextKeySelectedKeyID/Namesoselected_keyonly reflects a key that served a successful response. As a side effect, the telemetry plugin recorded empty strings forselected_key_id/selected_key_namelabels on failed requests, making it impossible to attribute failures to specific keys in metrics dashboards.Changes
plugins/telemetry/main.go: whenselectedKeyIDis empty, fall back to the last entry inattemptTrailto recover key ID and name before recording metrics labels.attemptTrailis the authoritative record of attempted keys percore/bifrost.go. The last entry represents the key associated with the final (failed) attempt. Metric labels for failed requests will now show this key rather than an empty string.Type of change
Affected areas
How to test
bifrost_requests_total) — verifyselected_key_idandselected_key_namelabels are populated for the failed request.Breaking changes
Related issues
Related to #3040 (same root cause, telemetry counterpart of the logging fix).
Security considerations
None. Key ID and name are already stored in attemptTrail; this change only reads from it.
Checklist