Skip to content

feat(core): Add streamGenAiSpans options to stream gen_ai spans#20785

Merged
andreiborza merged 9 commits into
developfrom
ab/gen-ai-streaming
May 12, 2026
Merged

feat(core): Add streamGenAiSpans options to stream gen_ai spans#20785
andreiborza merged 9 commits into
developfrom
ab/gen-ai-streaming

Conversation

@andreiborza
Copy link
Copy Markdown
Member

@andreiborza andreiborza commented May 11, 2026

We have concluded the experiment of streaming gen_ai spans as v2 envelope items via our 10.50.0-alpha.0 release and are now ready to pull this into stable gated behind a flag.

Adds a new experimental option streamGenAiSpans option that controls how gen_ai spans are sent to Sentry. When set, the SDK extracts all gen_ai spans out of a transaction and sends them as v2 envelope items.

This avoids payload size limits of regular transactions.

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  _experiments: {
    streamGenAiSpans: true,
  },
});

@andreiborza andreiborza requested a review from a team as a code owner May 11, 2026 04:25
@andreiborza andreiborza force-pushed the ab/gen-ai-streaming branch from 6299108 to ec170d6 Compare May 11, 2026 04:26
Comment thread packages/core/src/tracing/vercel-ai/index.ts Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 26.84 kB +1.79% +471 B 🔺
@sentry/browser - with treeshaking flags 25.28 kB +1.87% +463 B 🔺
@sentry/browser (incl. Tracing) 44.73 kB +1.12% +494 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 46.73 kB +0.57% +263 B 🔺
@sentry/browser (incl. Tracing, Profiling) 49.75 kB +1.08% +528 B 🔺
@sentry/browser (incl. Tracing, Replay) 84.38 kB +0.62% +515 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 73.81 kB +0.69% +499 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 89.08 kB +0.6% +531 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 101.71 kB +0.52% +523 B 🔺
@sentry/browser (incl. Feedback) 44.03 kB +1.15% +497 B 🔺
@sentry/browser (incl. sendFeedback) 31.66 kB +1.5% +466 B 🔺
@sentry/browser (incl. FeedbackAsync) 36.77 kB +1.36% +493 B 🔺
@sentry/browser (incl. Metrics) 27.93 kB +1.03% +282 B 🔺
@sentry/browser (incl. Logs) 28.08 kB +1.08% +298 B 🔺
@sentry/browser (incl. Metrics & Logs) 28.75 kB +1.01% +286 B 🔺
@sentry/react 28.59 kB +1.72% +482 B 🔺
@sentry/react (incl. Tracing) 47.01 kB +1.11% +516 B 🔺
@sentry/vue 31.75 kB +1.65% +515 B 🔺
@sentry/vue (incl. Tracing) 46.59 kB +1.09% +501 B 🔺
@sentry/svelte 26.86 kB +1.79% +472 B 🔺
CDN Bundle 29.24 kB +1.01% +291 B 🔺
CDN Bundle (incl. Tracing) 47.16 kB +0.41% +192 B 🔺
CDN Bundle (incl. Logs, Metrics) 30.61 kB +0.85% +255 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 48.28 kB +0.4% +191 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 69.94 kB +0.37% +254 B 🔺
CDN Bundle (incl. Tracing, Replay) 84.55 kB +0.22% +184 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 85.62 kB +0.24% +200 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 90.36 kB +0.23% +202 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 91.46 kB +0.23% +206 B 🔺
CDN Bundle - uncompressed 85.99 kB +1.19% +1.01 kB 🔺
CDN Bundle (incl. Tracing) - uncompressed 141.47 kB +0.67% +931 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 90.18 kB +1.14% +1.01 kB 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 144.93 kB +0.65% +931 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 215.01 kB +0.48% +1.01 kB 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 260.18 kB +0.36% +931 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 263.62 kB +0.36% +931 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 273.87 kB +0.35% +931 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 277.31 kB +0.34% +931 B 🔺
@sentry/nextjs (client) 49.52 kB +1.06% +516 B 🔺
@sentry/sveltekit (client) 45.23 kB +1.14% +509 B 🔺
@sentry/node-core 60.84 kB +0.42% +252 B 🔺
@sentry/node 165.98 kB +0.2% +325 B 🔺
@sentry/node - without tracing 73.96 kB +0.48% +352 B 🔺
@sentry/aws-serverless 108.07 kB +0.28% +300 B 🔺
@sentry/cloudflare (withSentry) - minified 170.66 kB +0.59% +994 B 🔺
@sentry/cloudflare (withSentry) 430.47 kB +0.49% +2.09 kB 🔺

View base workflow run

@andreiborza andreiborza force-pushed the ab/gen-ai-streaming branch from ec170d6 to 239fd1e Compare May 11, 2026 05:25
Comment thread packages/core/src/tracing/spans/extractGenAiSpans.ts
@andreiborza andreiborza force-pushed the ab/gen-ai-streaming branch 5 times, most recently from cf9559a to 5bf30b9 Compare May 11, 2026 07:46
Comment thread packages/core/src/tracing/spans/extractGenAiSpans.ts
Copy link
Copy Markdown
Member

@JPeer264 JPeer264 left a comment

Choose a reason for hiding this comment

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

Tests are failing

const genAiSpans = [];
const remainingSpans = [];

for (const span of event.spans) {
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.

q: Is this here only for the experimental phase? It seems quite inefficient to loop over all spans everytime.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We do have a guard that pre-checks if a trace has gen_ai spans so this only happens when we really do need to do it. But yea, this will be gone in the future once we have proper span streaming everywhere.

Comment thread CHANGELOG.md

Adds a new experimental option `streamGenAiSpans` option that controls how `gen_ai` spans are
sent to Sentry. When set, the SDK extracts all `gen_ai` spans out of a
transaction and sends them as v2 envelope items.
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.

q: Is it an important change if practically no one knows yet what a v2 envelope item is?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think so, the justification for it is in the next line:

This avoids payload size limits of regular transactions.

sendDefaultPii: true,
// debug: true,
integrations: [Sentry.vercelAIIntegration()],
_experiments: { streamGenAiSpans: true },
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.

l: Is it mandatory to add this option in the test config, even though nothing in the test has changed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch, some of these apps don't need this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed in bbc19b7.

Adds a new experimental option `streamGenAiSpans` option that controls how
`gen_ai` spans are sent to Sentry. When set, the SDK extracts all `gen_ai` spans
out of a transaction and sends them as v2 envelope items.

This avoids payload size limits of regular transactions.

```ts
Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  _experiments: {
    streamGenAiSpans: true,
  },
});
```

Closes: #20170
@andreiborza andreiborza force-pushed the ab/gen-ai-streaming branch from 5bf30b9 to 21aff86 Compare May 11, 2026 08:54
Comment thread packages/core/src/tracing/vercel-ai/index.ts
Comment thread packages/core/src/tracing/vercel-ai/index.ts
Comment thread packages/core/src/tracing/spans/spanJsonToStreamedSpan.ts
Comment thread packages/core/src/tracing/vercel-ai/index.ts Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 1 potential issue.

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 623e6f1. Configure here.

@andreiborza andreiborza requested a review from nicohrubec May 11, 2026 11:09
@andreiborza andreiborza force-pushed the ab/gen-ai-streaming branch from e9beaa5 to cc2e598 Compare May 11, 2026 11:17
Copy link
Copy Markdown
Member

@nicohrubec nicohrubec left a comment

Choose a reason for hiding this comment

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

lgtm. we already agreed on the approach before shipping the alpha and the rest is mainly test ports, which should hopefully be pretty much 1:1 ports to the span streaming format? maybe worth double checking on the strategy, but for me it sounds fine to ship this opt-in and then switch the default after a few weeks. thanks for doing this!

Comment thread CHANGELOG.md Outdated
sent to Sentry. When set, the SDK extracts all `gen_ai` spans out of a
transaction and sends them as v2 envelope items.

This avoids payload size limits of regular transactions.
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.

l: maybe worth it to be a bit more explicit about this? i.e. that this should be enabled if orgs run into the problem of spans being dropped because they are too large

@andreiborza andreiborza merged commit ad1f373 into develop May 12, 2026
519 of 523 checks passed
@andreiborza andreiborza deleted the ab/gen-ai-streaming branch May 12, 2026 02:30
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.

3 participants