Uh oh!
There was an error while loading. Please reload this page.
fix(ai): roll up OpenTelemetry usage across iterations - #928
Conversation
Warning Review limit reached
Next review available in:52 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe OpenTelemetry middleware now accumulates usage across chat iterations and applies it once to the root span on finish, error, or abort. Unit and E2E tests cover multi-iteration tool loops, per-iteration spans, metrics, and aggregated root attributes. ChangesOpenTelemetry root usage rollup
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant E2ETest
participant OtelUsageRoute
participant Chat
participant otelMiddleware
participant SpanExporter
E2ETest->>OtelUsageRoute: POST provider=tool-loop
OtelUsageRoute->>Chat: invoke chat with weatherTool
Chat->>otelMiddleware: emit usage for each iteration
otelMiddleware->>otelMiddleware: accumulate root usage
Chat->>otelMiddleware: finish after tool loop
otelMiddleware->>SpanExporter: export iteration spans and rolled-up root span
SpanExporter-->>E2ETest: return captured spans
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
dexhunter
commented
Jul 25, 2026
This rolls up numeric OpenTelemetry usage attributes across chat iterations onto the request root span, applying the accumulated totals once before the root |
027dbf8 to
9ea1a12Comparetombeckenham
commented
Aug 10, 2026
Maintainer sweep: rebased onto |
View your CI Pipeline Execution ↗ for commit 9ea1a12
☁️ Nx Cloud last updated this comment at |
@tanstack/ai@tanstack/ai-acp@tanstack/ai-angular@tanstack/ai-anthropic@tanstack/ai-bedrock@tanstack/ai-byteplus@tanstack/ai-claude-code@tanstack/ai-client@tanstack/ai-code-mode@tanstack/ai-code-mode-skills@tanstack/ai-codex@tanstack/ai-devtools-core@tanstack/ai-durable-stream@tanstack/ai-elevenlabs@tanstack/ai-event-client@tanstack/ai-fal@tanstack/ai-gemini@tanstack/ai-grok@tanstack/ai-grok-build@tanstack/ai-groq@tanstack/ai-isolate-cloudflare@tanstack/ai-isolate-daytona@tanstack/ai-isolate-node@tanstack/ai-isolate-quickjs@tanstack/ai-isolate-quickjs-bun@tanstack/ai-mcp@tanstack/ai-memory@tanstack/ai-mistral@tanstack/ai-ollama@tanstack/ai-openai@tanstack/ai-opencode@tanstack/ai-openrouter@tanstack/ai-persistence@tanstack/ai-preact@tanstack/ai-react@tanstack/ai-react-ui@tanstack/ai-sandbox@tanstack/ai-sandbox-cloudflare@tanstack/ai-sandbox-daytona@tanstack/ai-sandbox-docker@tanstack/ai-sandbox-local-process@tanstack/ai-sandbox-sprites@tanstack/ai-sandbox-vercel@tanstack/ai-solid@tanstack/ai-solid-ui@tanstack/ai-svelte@tanstack/ai-utils@tanstack/ai-vue@tanstack/ai-vue-ui@tanstack/openai-base@tanstack/preact-ai-devtools@tanstack/react-ai-devtools@tanstack/solid-ai-devtoolscommit: |
Uh oh!
There was an error while loading. Please reload this page.
Summary
onSpanEndcallback on finish, error, and abort pathsProvenance
Weco supplied the request-level accumulator direction. The strict evaluator rejected its initial field mapping, so the final implementation was rebuilt through the existing
usageAttributes()contract and hardened across every terminal path. Public autoresearch trajectoryValidation
root_usage_abs_error_tokensimproved from550to0; finish, error, and abort fixtures passedpnpm --filter @tanstack/ai test:lib --run tests/middlewares/otel.test.ts(50tests passed)pnpm --filter @tanstack/ai test:lib(1,137tests passed)pnpm --filter @tanstack/ai test:typespnpm --filter @tanstack/ai test:eslint(no errors; existing warnings only)pnpm --filter @tanstack/ai-e2e test:types347tests with one skipped, one retry-only flaky test, and one environment-only MiniflareEPIPEfailure that reproduces on the unchanged baseCI=1 pnpm test:prgit diff --checkConflict Review
PR #896 changes adjacent usage-attribute tests and E2E helpers but does not implement request-level root-span rollup. It may require a small test/helper rebase if merged first; it is not a behavioral duplicate of this fix.
Fixes#916
Summary by CodeRabbit
Bug Fixes
Tests