Skip to content

feat: Span Streaming (WIP)#19119

Draft
Lms24 wants to merge 4 commits intodevelopfrom
lms/feat-span-first
Draft

feat: Span Streaming (WIP)#19119
Lms24 wants to merge 4 commits intodevelopfrom
lms/feat-span-first

Conversation

@Lms24
Copy link
Member

@Lms24 Lms24 commented Feb 2, 2026

This PR introduces span v2 types as defined in our [develop
spec](https://develop.sentry.dev/sdk/telemetry/spans/span-protocol/):

* Envelope types:
* `SpanV2Envelope`, `SpanV2EnvelopeHeaders`, `SpanContainerItem`,
`SpanContainerItemHeaders`
* Span v2 types:
* `SpanV2JSON` the equivalent to today's `SpanJSON`. Users will interact
with spans in this format in `beforeSendSpan`. SDK integrations will use
this format in `processSpan` (and related) hooks.
* `SerializedSpan` the final, serialized format for v2 spans, sent in
the envelope container item.

Closes #19101 (added automatically)

ref #17836
@Lms24 Lms24 changed the title feat(core): Add span v2 and envelope type definitions (#19100) feat: Span Streaming (WIP) Feb 2, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

Codecov Results 📊

143 passed | ⏭️ 3 skipped | Total: 146 | Pass Rate: 97.95% | Execution Time: 9m 44s

All tests are passing successfully.


Generated by Codecov Action

@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,093 - 9,086 +0%
GET With Sentry 1,713 19% 1,653 +4%
GET With Sentry (error only) 6,134 67% 6,094 +1%
POST Baseline 1,208 - 1,166 +4%
POST With Sentry 609 50% 539 +13%
POST With Sentry (error only) 1,073 89% 1,027 +4%
MYSQL Baseline 3,389 - 3,282 +3%
MYSQL With Sentry 533 16% 393 +36%
MYSQL With Sentry (error only) 2,720 80% 2,680 +1%

View base workflow run

@Lms24 Lms24 self-assigned this Feb 2, 2026
Lms24 and others added 3 commits February 4, 2026 14:25
…ility utilities (#19120)

This adds the foundation for user-facing 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`
Adds a utility to create a span v2 envelope from a `SerializedSpan`
array + tests.

Note: I think here, the "v2" naming makes more sense than the
`StreamSpan` patter we use for user-facing functionality. This function
should never be called by users, and the envelope is type `span` with
content type `span.v2+json`

ref #17836
This PR adds span JSON conversion and serialization helpers for span
streaming:

* `spanToStreamedSpanJSON`: Converts a `Span` instance to a JSON object
used as intermediate representation as outlined in
#19100
* Adds `SentrySpan::getStreamedSpanJSON` method to convert our own spans
  * Directly converts any OTel spans
  * This is analogous to how `spanToJSON` works today.
* `spanJsonToSerializedSpan`: Converts a `StreamedSpanJSON` into the
final `SerializedSpan` to be sent to Sentry.

This PR also adds unit tests for both helpers.

ref #17836

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Jan Peer Stöcklmair <jan.peer@sentry.io>
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.

Span Streaming Implementation

1 participant