Repository navigation
feat(llm): nest OpenRouter Broadcast traces under the calling span - #829
Conversation
OpenRouter's Broadcast exporter uses the request's trace.trace_id and trace.parent_span_id verbatim as W3C ids (verified against prod on 2026-09-10). Stamp the current span's ids on every OpenRouter chat request, in the same HTTP-client transform that adds usage accounting, so the LLM Generation trace it emits (provider attempts, fallbacks, router latency) lands inside Maple's own trace instead of arriving as a twin trace that only shares a session id.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughOpenRouter request transformation now injects usage reporting and current span identifiers. Existing trace fields remain intact. A live test verifies trace propagation, parent span ID format, and usage metadata. ChangesOpenRouter per-call fields
Estimated code review effort: 3 (Moderate) | ~20 minutes Severity of issue fixed: Low Sequence Diagram(s)sequenceDiagram
participant ChatSpan
participant OpenRouterClient
participant withPerCallFields
participant OpenRouter
ChatSpan->>OpenRouterClient: create request within chat span
OpenRouterClient->>withPerCallFields: transform JSON request body
withPerCallFields->>ChatSpan: read trace and parent span identifiers
ChatSpan-->>withPerCallFields: return span identifiers
withPerCallFields-->>OpenRouterClient: return request with usage and trace fields
OpenRouterClient->>OpenRouter: send transformed request
Suggested reviewers: Merge Risk: ⚪ Minimal · up to OpenRouter requests now nest under the calling chat trace while preserving usage metadata. The supplied validation covers the changed behavior, so the change is mergeable. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Summary
openroutertrace per LLM call, linked to ours only bysession_id(doubled session usage until fix(agent-sessions): count a model call's usage once — nested buckets, gateway mirrors, sub-steps #766's response-id dedupe).trace.trace_id/trace.parent_span_idverbatim as W3C ids.withUsageAccounting→withPerCallFields: the same HTTP-client body transform now also merges the current span'straceId/spanIdintotrace, keeping the per-layertrace_name. No span in scope → onlyusageis spliced.LLM Generation+provider attempt Nspans nest under Maple'schatspan, so the waterfall shows provider fallbacks anddeepestReporterSumnets the usage within one trace.Test plan
Llm.test.ts:trace_idmatches the enclosing span,parent_span_idis 16-hex,usage.includeintact (21/21)ServiceName='openrouter'rows share thechatspan'sTraceId; Agent Sessions totals not doubledNeed help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit