Skip to content

feat(core): Add SpanBuffer implementation#19204

Open
Lms24 wants to merge 3 commits intolms/feat-span-firstfrom
lms/feat-core-spanBuffer
Open

feat(core): Add SpanBuffer implementation#19204
Lms24 wants to merge 3 commits intolms/feat-span-firstfrom
lms/feat-core-spanBuffer

Conversation

@Lms24
Copy link
Member

@Lms24 Lms24 commented Feb 6, 2026

This PR adds a simple span buffer implementation to be used for buffering streamed spans.

Behaviour:

  • buckets incoming spans by traceId, as we must not mix up spans of different traces in one envelope
  • flushes the entire buffer every 5s by default
  • flushes the specific trace bucket if the max span limit (1000) is reached. Relay accepts at max. 1000 spans per envelope
  • computes the DSC when flushing the first span of a trace. This is the latest time we can do it as once we flushed we have to freeze the DSC for Dynamic Sampling consistency
  • debounces the flush interval whenever we flush
  • flushes the entire buffer if Sentry.flush is called
  • [implicit] Client report generation for dropped envelopes is handled in the transport

Methods:

  • add accepts a new span to be enqueued into the buffer
  • drain flushes the entire buffer
  • flush(traceId) flushes a specific traceId bucket. This can be used by e.g. the browser span streaming implementation to flush out the trace of a segment span directly once it ends.

Options:

  • maxSpanLimit - allows to configure a 0 < maxSpanLimit < 1000 custom span limit. Useful for testing but we could also expose this to users if we see a need
  • flushInterval- allows to configure a >0 flush interval

Limitations/edge cases:

  • No maximum limit of concurrently buffered traces. I'd tend to accept this for now and see where this leads us in terms of memory pressure but at the end of the day, the interval based flushing, in combination with our promise buffer should avoid an ever-growing map of trace buckets. Happy to change this if reviewers have strong opinions or I'm missing something important!
  • There's no priority based scheduling relative to other telemetry items. Just like with our other log and metric buffers.
  • since Map is insertion order preserving, meaning we apply a FIFO strategy whendraining the trace buckets. This is in line with our develop spec for the telemetry processor but might lead to cases where new traces are dropped by the promise buffer if a lof of concurrently running traces are flushed. I think that's a fine trade off.

ref #19119

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

Codecov Results 📊


Generated by Codecov Action

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.44 kB added added
@sentry/browser - with treeshaking flags 23.91 kB added added
@sentry/browser (incl. Tracing) 42.4 kB added added
@sentry/browser (incl. Tracing, Profiling) 47.05 kB added added
@sentry/browser (incl. Tracing, Replay) 81.08 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.65 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 85.78 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 97.95 kB added added
@sentry/browser (incl. Feedback) 42.16 kB added added
@sentry/browser (incl. sendFeedback) 30.12 kB added added
@sentry/browser (incl. FeedbackAsync) 35.14 kB added added
@sentry/browser (incl. Metrics) 26.56 kB added added
@sentry/browser (incl. Logs) 26.71 kB added added
@sentry/browser (incl. Metrics & Logs) 27.37 kB added added
@sentry/react 27.17 kB added added
@sentry/react (incl. Tracing) 44.65 kB added added
@sentry/vue 30.04 kB added added
@sentry/vue (incl. Tracing) 44.21 kB added added
@sentry/svelte 25.45 kB added added
CDN Bundle 27.98 kB added added
CDN Bundle (incl. Tracing) 43.17 kB added added
CDN Bundle (incl. Logs, Metrics) 28.82 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 44.02 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 67.77 kB added added
CDN Bundle (incl. Tracing, Replay) 79.92 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 80.8 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 85.38 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.28 kB added added
CDN Bundle - uncompressed 81.84 kB added added
CDN Bundle (incl. Tracing) - uncompressed 127.84 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 84.67 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.67 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.05 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 244.44 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 247.26 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 257.24 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 260.05 kB added added
@sentry/nextjs (client) 46.99 kB added added
@sentry/sveltekit (client) 42.78 kB added added
@sentry/node-core 52.19 kB added added
@sentry/node 166.37 kB added added
@sentry/node - without tracing 93.97 kB added added
@sentry/aws-serverless 109.48 kB added added

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 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,339 - - added
GET With Sentry 1,703 18% - added
GET With Sentry (error only) 6,158 66% - added
POST Baseline 1,202 - - added
POST With Sentry 602 50% - added
POST With Sentry (error only) 1,032 86% - added
MYSQL Baseline 3,294 - - added
MYSQL With Sentry 569 17% - added
MYSQL With Sentry (error only) 2,647 80% - added

@Lms24 Lms24 self-assigned this Feb 6, 2026
@Lms24 Lms24 force-pushed the lms/feat-core-spanBuffer branch from e96091e to a1dc134 Compare February 6, 2026 13:38
@Lms24
Copy link
Member Author

Lms24 commented Feb 6, 2026

cc @isaacs tagged you for a review since you worked on the telemetry buffer and might see something I missed in this simplified implementation

Base automatically changed from lms/feat-core-captureSpan to lms/feat-span-first February 6, 2026 14:08
@Lms24 Lms24 force-pushed the lms/feat-core-spanBuffer branch from a1dc134 to 471048d Compare February 6, 2026 15:11
@Lms24 Lms24 marked this pull request as ready for review February 6, 2026 15:11
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 3 potential issues.

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

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.

1 participant