Skip to content

Conversation

@Lms24
Copy link
Member

@Lms24 Lms24 commented Feb 2, 2026

Summary

This PR adds the foundation for span streaming configuration:

  • traceLifecycle option: New option in ClientOptions that controls whether spans are sent statically (when the entire local span tree is complete) or streamed (in batches following interval- and action-based triggers).

Because the span JSON will look different for streamed spans vs. static spans (i.e. our current ones, we also need some helpers for beforeSendSpan where users consume and interact with StreamedSpanJSON:

  • withStreamedSpan() utility: Wrapper function that marks a beforeSendSpan callback as compatible with the streamed span format (StreamedSpanJSON)

  • isStreamedBeforeSendSpanCallback() type guard: Internal utility to check if a callback was wrapped with withStreamedSpan

Usage Example

Sentry.init({
  traceLifecycle: 'stream',
  beforeSendSpan: withStreamedSpan((span) => {
    // span is of type StreamedSpanJSON
    return span;
  }),
});

ref #17836

Adds support for span streaming configuration:

- Add `traceLifecycle` option to ClientOptions ('static' | 'stream')
- Add `BeforeSendSpanCallback` type with optional `_streamed` marker
- Add `withStreamedSpan()` utility to wrap callbacks for streamed spans
- Add `isStreamedBeforeSendSpanCallback()` type guard utility

This is part of the span streaming feature that allows spans to be sent
incrementally rather than waiting for the full trace to complete.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

Codecov Results 📊


Generated by Codecov Action

@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.43 kB added added
@sentry/browser - with treeshaking flags 23.89 kB added added
@sentry/browser (incl. Tracing) 42.25 kB added added
@sentry/browser (incl. Tracing, Profiling) 46.88 kB added added
@sentry/browser (incl. Tracing, Replay) 80.88 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.48 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 85.58 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 97.76 kB added added
@sentry/browser (incl. Feedback) 42.15 kB added added
@sentry/browser (incl. sendFeedback) 30.11 kB added added
@sentry/browser (incl. FeedbackAsync) 35.12 kB added added
@sentry/browser (incl. Metrics) 26.55 kB added added
@sentry/browser (incl. Logs) 26.7 kB added added
@sentry/browser (incl. Metrics & Logs) 27.36 kB added added
@sentry/react 27.16 kB added added
@sentry/react (incl. Tracing) 44.48 kB added added
@sentry/vue 29.88 kB added added
@sentry/vue (incl. Tracing) 44.05 kB added added
@sentry/svelte 25.45 kB added added
CDN Bundle 27.96 kB added added
CDN Bundle (incl. Tracing) 43.02 kB added added
CDN Bundle (incl. Logs, Metrics) 28.8 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 43.85 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 67.75 kB added added
CDN Bundle (incl. Tracing, Replay) 79.76 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 80.62 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 85.2 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.11 kB added added
CDN Bundle - uncompressed 81.78 kB added added
CDN Bundle (incl. Tracing) - uncompressed 127.35 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 84.61 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.18 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 207.99 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 243.95 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 246.77 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 256.75 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 259.56 kB added added
@sentry/nextjs (client) 46.85 kB added added
@sentry/sveltekit (client) 42.63 kB added added
@sentry/node-core 52.17 kB added added
@sentry/node 166.22 kB added added
@sentry/node - without tracing 93.95 kB added added
@sentry/aws-serverless 109.46 kB added added

@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 9,126 - - added
GET With Sentry 1,659 18% - added
GET With Sentry (error only) 6,120 67% - added
POST Baseline 1,205 - - added
POST With Sentry 586 49% - added
POST With Sentry (error only) 1,063 88% - added
MYSQL Baseline 3,375 - - added
MYSQL With Sentry 498 15% - added
MYSQL With Sentry (error only) 2,714 80% - added

@Lms24 Lms24 changed the title feat(core): Add traceLifecycle option and beforeSendSpan utilities feat(core): Add traceLifecycle option and beforeSendSpan compatibility utilities Feb 2, 2026
@Lms24 Lms24 self-assigned this Feb 2, 2026
@Lms24 Lms24 marked this pull request as ready for review February 2, 2026 16:23
Copy link

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

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

* When true, indicates this callback is designed to handle the {@link StreamedSpanJSON} format
* used with `traceLifecycle: 'stream'`. Set this by wrapping your callback with `withStreamedSpan`.
*/
_streamed?: true;
Copy link
Member

Choose a reason for hiding this comment

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

M: As only true is allowed here, we might need to set this type to true | undefined in case someone enabled exactOptionalPropertyTypes.

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