feat(core): Add streamGenAiSpans options to stream gen_ai spans#20785
Conversation
6299108 to
ec170d6
Compare
size-limit report 📦
|
ec170d6 to
239fd1e
Compare
cf9559a to
5bf30b9
Compare
| const genAiSpans = []; | ||
| const remainingSpans = []; | ||
|
|
||
| for (const span of event.spans) { |
There was a problem hiding this comment.
q: Is this here only for the experimental phase? It seems quite inefficient to loop over all spans everytime.
There was a problem hiding this comment.
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.
|
|
||
| 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. |
There was a problem hiding this comment.
q: Is it an important change if practically no one knows yet what a v2 envelope item is?
There was a problem hiding this comment.
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 }, |
There was a problem hiding this comment.
l: Is it mandatory to add this option in the test config, even though nothing in the test has changed?
There was a problem hiding this comment.
Good catch, some of these apps don't need this.
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
5bf30b9 to
21aff86
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
e9beaa5 to
cc2e598
Compare
nicohrubec
left a comment
There was a problem hiding this comment.
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!
| 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. |
There was a problem hiding this comment.
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

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
streamGenAiSpansoption that controls howgen_aispans are sent to Sentry. When set, the SDK extracts allgen_aispans out of a transaction and sends them as v2 envelope items.This avoids payload size limits of regular transactions.