feat(core)!: Make beforeSendSpan compatible with streamed spans by default - #22643
Open
Lms24 wants to merge 7 commits into
Open
feat(core)!: Make beforeSendSpan compatible with streamed spans by default#22643Lms24 wants to merge 7 commits into
beforeSendSpan compatible with streamed spans by default#22643Lms24 wants to merge 7 commits into
Conversation
Contributor
size-limit report 📦
|
Lms24
force-pushed
the
feat/before-send-span-streamed-default
branch
from
July 27, 2026 08:41
a32a10f to
bec33b0
Compare
Lms24
force-pushed
the
feat/before-send-span-streamed-default
branch
from
July 27, 2026 14:58
bec33b0 to
e303625
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 e303625. Configure here.
Lms24
force-pushed
the
feat/before-send-span-streamed-default
branch
2 times, most recently
from
July 28, 2026 08:22
a6f845e to
344055e
Compare
beforeSendSpan compatible with streamed spans by default
Lms24
force-pushed
the
feat/before-send-span-streamed-default
branch
from
July 29, 2026 14:51
ec83b6f to
9f59f8c
Compare
Make streamed span JSON the default beforeSendSpan contract and provide withStaticSpan for callbacks that still process transaction span JSON. Deprecate withStreamedSpan for removal in version 12. BREAKING CHANGE: beforeSendSpan receives StreamedSpanJSON by default. Fixes #22349 Co-Authored-By: Cursor <cursoragent@cursor.com> Co-authored-by: Cursor <cursoragent@cursor.com>
`withStreamedSpan` no longer marks its callback. Nothing reads `_streamed` since `isStreamedBeforeSendSpanCallback` became "not wrapped with `withStaticSpan`", so the wrapper returns the callback unchanged instead of mutating a function it was handed. Resolve `traceLifecycle` once in the `Client` constructor, where any value other than `'static'` normalizes to the `'stream'` default. Neither span streaming integration writes back to the option anymore, which removes an ordering hazard: integrations that read `hasSpanStreamingEnabled` during their own `setup` could observe the value before or after the mutation depending on integration order. The registration gates now test `!== 'static'` so they agree with the normalized value; previously an unknown value failed the gate but still resolved to `'stream'`, leaving nothing to flush spans. Move the `beforeSendSpan` format check into the constructor as well. A callback is only invoked for the span format matching the trace lifecycle, so a mismatch means it is never called. The client can warn where the integration could not: with `traceLifecycle: 'static'` the streaming integration is never registered, so an unwrapped callback previously went unreported. A `withStaticSpan` callback under `traceLifecycle: 'stream'` no longer downgrades the lifecycle to `'static'`. Opting out of streaming requires setting `traceLifecycle: 'static'` explicitly. Refs #22349 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Lms24
force-pushed
the
feat/before-send-span-streamed-default
branch
from
July 29, 2026 15:37
9f59f8c to
9176c4b
Compare
Lms24
marked this pull request as ready for review
July 29, 2026 15:42
Lms24
requested review from
nicohrubec and
s1gr1d
and removed request for
a team
July 29, 2026 15:42
Lms24
requested review from
isaacs,
msonnb and
mydea
and removed request for
a team
July 29, 2026 15:43
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR changes
beforeSendSpanto receiveStreamedSpanJSONby default, matching the new trace lifecycle default.Callbacks that intentionally process legacy transaction span JSON need to add the
withStaticSpanwrapper that marks the callback as "static"-compatible and hands users theSpanJSONtype they used in the callback beforehand.The
withStreamedSpanwrapper remains available as a deprecated compatibility helper and is scheduled for removal in version 12.More changes:
beforeSendSpancallbacks no longer lead to switching thetraceLifecycle. Since it now has a default and users need to actively opt out of span streaming, I think it's fair to treat incompatible callbacks as "invalid" and hence skip over them.beforeSendSpancompatibility checks were moved from the integrations into the core client which ensures that they always run now, even if users selected thestaticlife cycle and hencespanStreamingIntegrationdoesn't get added.SpanJSON) spans in favour of always sending them as v2 spans, we now convert aStreamedSpanJsontoSpanJsonincaptureSpan, hand it to the static callback and then convert it back. Not great but I think we need to let users still scrub INP spans.Closes #22349