FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(core): Emit low-cardinality gen_ai inference span names when streaming by RulaKhaled · Pull Request #23573 · getsentry/sentry-javascript · GitHub

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 commented Aug 25, 2026
edited
Loading

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 Bot commented Aug 25, 2026

Copy link
Copy Markdown

JS-3410

github-actions Bot commented Aug 25, 2026
edited
Loading

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 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 marked this pull request as ready for review August 25, 2026 14:15
RulaKhaled requested review from a team as code owners August 25, 2026 14:15
RulaKhaled requested review from JPeer264 and isaacs and removed request for a team August 25, 2026 14:15
RulaKhaled self-assigned this Aug 25, 2026

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

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

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

❌ 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.

…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 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 merged commit 5fce2a3 into develop Aug 27, 2026
390 of 394 checks passed
RulaKhaled deleted the rolaabuhasna/js-3410-emit-low-cardinality-gen-ai-inference-span-names branch August 27, 2026 11:43
RulaKhaled added a commit that referenced this pull request Aug 28, 2026
… streaming (#23582)

With span streaming enabled (the default), `gen_ai.invoke_agent` names
follow the [agent span name
conventions](https://getsentry.github.io/sentry-conventions/names/#gen_ai-agent):
`{operation} {name}` from `gen_ai.agent.name`, `gen_ai.pipeline.name` or
`gen_ai.function_id`, otherwise `{operation}`.

In practice this only changes LangChain chain spans, and only their
prefix. They were named `chain format_prompt`, which does not lead with
the operation like every other agent span; they are now `invoke_agent
format_prompt`. The chain name itself is bounded, so it stays in the
name. A chain the SDK cannot name falls back to `invoke_agent` rather
than carrying the `unknown_chain` sentinel, the same way a missing model
is dropped in #23573.

LangGraph agent names and Vercel AI `functionId`s are unchanged in both
lifecycles — both are bounded, low-cardinality values.

The `pipeline.name` and `function_id` templates are added in
getsentry/sentry-conventions#593. LangChain still emits its chain name
on `langchain.chain.name`; moving it to `gen_ai.pipeline.name` is
tracked in
[JS-3452](https://linear.app/getsentry/issue/JS-3452/move-langchainchainname-to-gen-aipipelinename)
and should land before v11 ships, so the emitted name matches a
published template. Span names are unaffected by that move — they are
built from the local chain name, not read back off the attribute.

The other two ops in the agent rule need nothing: the SDK emits no
`gen_ai.handoff` spans, and `gen_ai.create_agent` was dropped in v11.
Neither is listed in the migration table.

The migration entry lives in `MIGRATION.md` rather than
`docs/migration/v11-end-state.md`, which was removed by #23623.

Fixes #23524

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
zkasuran added a commit to zkasuran/sentry-javascript that referenced this pull request Aug 28, 2026
Two conflicts, both in the google-genai instrumentation that develop moved under us.

packages/server-utils/src/ai/google-genai/index.ts: develop added low-cardinality
span names when span streaming is on (getsentry#23573) and dropped the captureException
calls from the instrumentation (getsentry#23024), touching the same lines where this branch
threads the chat create-time params through. Kept both: the merged apply() computes
attributeParams via mergeChatCreateParams, feeds those to extractRequestAttributes
plus addPrivateRequestAttributes, then derives model with develop's || 'unknown' and
its spanName sentinel logic.

packages/server-utils/test/ai/lib/tracing/google-genai.test.ts: add/add, develop
landed a span-names suite at the same path this branch used for the config suite.
Took develop's file whole and re-added the config suite beside it, hoisting the
shared setupClient to module scope and switching the config assertions from
spanToJSON to spanToStaticSpanJSON, since spanToJSON now returns the streamed shape
(attributes, no data).

Also updated the Cloudflare integration test. Its chat span assertion matches
attributes exhaustively with toEqual, while that scenario passes a config to
chats.create, so propagating it adds temperature, top_p and max_tokens to the chat
span. Verified the assertion fails without those three keys and passes with them.
The node suites assert per key, so they were unaffected.

Verified: @sentry/server-utils 432 tests passing (44 files), node google-genai and
google-genai-v2 integration 24 passing, cloudflare google-genai integration 1
passing, oxfmt --check, oxlint --type-aware, oxlint src --type-aware --type-check.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL