Skip to content

feat(core): Emit low-cardinality gen_ai inference span names when streaming - #23573

Merged
RulaKhaled merged 1 commit into
developfrom
rolaabuhasna/js-3410-emit-low-cardinality-gen-ai-inference-span-names
Aug 27, 2026
Merged

feat(core): Emit low-cardinality gen_ai inference span names when streaming#23573
RulaKhaled merged 1 commit into
developfrom
rolaabuhasna/js-3410-emit-low-cardinality-gen-ai-inference-span-names

Conversation

@RulaKhaled

@RulaKhaled RulaKhaled commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

When span streaming is enabled, gen_ai inference span names follow the inference templates: {operation} {model} when a model is known, {operation} when it is not. Instrumented methods always have an operation, so the convention fallback Generative AI model operation is not emitted today.

traceLifecycle: 'static' keeps the previous names (chat unknown). Known models stay in the name in both lifecycles (chat gpt-4).

The inference ops the SDK emits are gen_ai.chat, gen_ai.embeddings, gen_ai.generate_content and gen_ai.rerank — the last three were only added to the conventions' inference rule in sentry-conventions#579, but the naming here is derived from the operation rather than hardcoded per op, so they were already covered. The Vercel AI channel path never emitted an unknown model sentinel, so its names were already conformant; a test now locks that in. The SDK emits no gen_ai.responses or gen_ai.text_completion spans.

gen_ai.execute_tool spans keep the tool name in their name (execute_tool getWeather) — the tool name is a bounded, resolved value, so it behaves like a known model rather than a high-cardinality identifier. Agent ops (gen_ai.invoke_agent, gen_ai.create_agent, gen_ai.handoff) are out of scope here and handled in #23582 (JS-3409).

Fixes #23525

@linear-code

linear-code Bot commented Aug 25, 2026

Copy link
Copy Markdown

JS-3410

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.57 kB - -
@sentry/browser - with treeshaking flags 26.92 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.82 kB - -
@sentry/browser (incl. Tracing) 48.63 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.65 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.56 kB - -
@sentry/browser (incl. Tracing, Replay) 88.11 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.51 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 92.82 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 105.51 kB - -
@sentry/browser (incl. Feedback) 45.79 kB - -
@sentry/browser (incl. sendFeedback) 33.35 kB - -
@sentry/browser (incl. FeedbackAsync) 38.46 kB - -
@sentry/browser (incl. Metrics) 29.51 kB - -
@sentry/browser (incl. Logs) 29.8 kB - -
@sentry/browser (incl. Metrics & Logs) 30.43 kB - -
@sentry/react 30.31 kB - -
@sentry/react (incl. Tracing) 50.84 kB - -
@sentry/vue 35.69 kB - -
@sentry/vue (incl. Tracing) 50.88 kB - -
@sentry/svelte 28.59 kB - -
CDN Bundle 30.36 kB - -
CDN Bundle (incl. Tracing) 49.12 kB - -
CDN Bundle (incl. Logs, Metrics) 32.56 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 51.01 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73 kB - -
CDN Bundle (incl. Tracing, Replay) 86.62 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.52 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 92.4 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.33 kB - -
CDN Bundle - uncompressed 89.97 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.82 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.26 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.51 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.42 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.32 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 272 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 280.01 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.68 kB - -
@sentry/nextjs (client) 53.41 kB - -
@sentry/sveltekit (client) 49.08 kB - -
@sentry/core/server 65.3 kB - -
@sentry/core/browser 52.37 kB - -
@sentry/node 122.5 kB +0.15% +179 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.22 kB - -
@sentry/node - without tracing 87.66 kB +0.03% +22 B 🔺
@sentry/node - without channel injection 102.19 kB +0.17% +166 B 🔺
@sentry/aws-serverless 95.82 kB +0.03% +24 B 🔺
@sentry/cloudflare (withSentry) - minified 199.61 kB +0.02% +37 B 🔺
@sentry/cloudflare (withSentry) 495.94 kB +0.05% +232 B 🔺

View base workflow run

@RulaKhaled
RulaKhaled force-pushed the rolaabuhasna/js-3410-emit-low-cardinality-gen-ai-inference-span-names branch from dac5b71 to 314f52f Compare August 25, 2026 13:50
@RulaKhaled
RulaKhaled marked this pull request as ready for review August 25, 2026 14:15
@RulaKhaled
RulaKhaled requested review from a team as code owners August 25, 2026 14:15
@RulaKhaled
RulaKhaled requested review from JPeer264 and isaacs and removed request for a team August 25, 2026 14:15
@RulaKhaled RulaKhaled self-assigned this Aug 25, 2026

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some opportunities for a bit of factoring to reduce the overhead here and prune some dead fallback branches, but that can also be done in a subsequent followup.

Comment thread packages/server-utils/src/ai/anthropic-ai/index.ts Outdated
Comment thread packages/server-utils/src/ai/anthropic-ai/index.ts Outdated
Comment thread packages/server-utils/src/ai/openai/index.ts Outdated
Comment thread packages/server-utils/src/ai/workers-ai/index.ts Outdated
Comment thread packages/server-utils/src/ai/anthropic-ai/index.ts Outdated

@JPeer264 JPeer264 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isaac already brought up great points. Other then his points - LGTM

@RulaKhaled
RulaKhaled force-pushed the rolaabuhasna/js-3410-emit-low-cardinality-gen-ai-inference-span-names branch from d21d777 to 41dfc75 Compare August 26, 2026 09:30
Comment thread packages/server-utils/src/ai/workers-ai/index.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 16742a1. Configure here.

Comment thread packages/server-utils/src/ai/langchain/index.ts
Comment thread packages/server-utils/src/integrations/anthropic.ts
…when streaming

When span streaming is on, inference spans use `{operation} {model}`, or
`{operation}` when the model is missing or empty. `gen_ai.execute_tool`
drops the tool name from the span name, which stays on `gen_ai.tool.name`.
Static lifecycle names are unchanged.

Every instrumented method supplies an operation, so the convention
fallback `Generative AI model operation` is unreachable and is not wired
up at any site.
@RulaKhaled
RulaKhaled force-pushed the rolaabuhasna/js-3410-emit-low-cardinality-gen-ai-inference-span-names branch from 3b5da13 to b7aa981 Compare August 27, 2026 10:44
@RulaKhaled
RulaKhaled merged commit 5fce2a3 into develop Aug 27, 2026
390 of 394 checks passed
@RulaKhaled
RulaKhaled deleted the rolaabuhasna/js-3410-emit-low-cardinality-gen-ai-inference-span-names branch August 27, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit low cardinality gen_ai inference span names

4 participants