Skip to content

feat(core): Add span serialization utilities - #19140

Merged
Lms24 merged 11 commits into
lms/feat-span-firstfrom
lms/span-first-pr7-span-serialization
Feb 4, 2026
Merged

feat(core): Add span serialization utilities#19140
Lms24 merged 11 commits into
lms/feat-span-firstfrom
lms/span-first-pr7-span-serialization

Conversation

@Lms24

@Lms24Lms24 commented Feb 3, 2026

Copy link
Copy Markdown
Member

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 feat(core/spans): Add span v2 and envelope type definitions #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

This PR adds utilities for serializing spans to the new V2 format:
- `spanToV2JSON`: Converts a span to SerializedSpan (V2 format)
- `getV2SpanLinks`: Converts span links with serialized attributes
- `getV2StatusMessage`: Converts status to 'ok' | 'error'
- `INTERNAL_getSegmentSpan`: Renamed from getRootSpan (with alias kept)
These utilities are needed for the span streaming feature and will be
used by subsequent PRs to serialize spans before sending.
Co-authored-by: Cursor <cursoragent@cursor.com>
Comment threadpackages/core/src/utils/spanUtils.ts
@Lms24
Lms24 marked this pull request as draft February 3, 2026 14:54
@github-actions

github-actionsBot commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊


Generated by Codecov Action

@github-actions

github-actionsBot commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser25.44 kBaddedadded
@sentry/browser - with treeshaking flags23.91 kBaddedadded
@sentry/browser (incl. Tracing)42.39 kBaddedadded
@sentry/browser (incl. Tracing, Profiling)47.04 kBaddedadded
@sentry/browser (incl. Tracing, Replay)81.07 kBaddedadded
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags70.64 kBaddedadded
@sentry/browser (incl. Tracing, Replay with Canvas)85.77 kBaddedadded
@sentry/browser (incl. Tracing, Replay, Feedback)97.94 kBaddedadded
@sentry/browser (incl. Feedback)42.16 kBaddedadded
@sentry/browser (incl. sendFeedback)30.12 kBaddedadded
@sentry/browser (incl. FeedbackAsync)35.13 kBaddedadded
@sentry/browser (incl. Metrics)26.55 kBaddedadded
@sentry/browser (incl. Logs)26.7 kBaddedadded
@sentry/browser (incl. Metrics & Logs)27.36 kBaddedadded
@sentry/react27.17 kBaddedadded
@sentry/react (incl. Tracing)44.64 kBaddedadded
@sentry/vue30.03 kBaddedadded
@sentry/vue (incl. Tracing)44.2 kBaddedadded
@sentry/svelte25.45 kBaddedadded
CDN Bundle27.98 kBaddedadded
CDN Bundle (incl. Tracing)43.14 kBaddedadded
CDN Bundle (incl. Logs, Metrics)28.81 kBaddedadded
CDN Bundle (incl. Tracing, Logs, Metrics)43.98 kBaddedadded
CDN Bundle (incl. Replay, Logs, Metrics)67.76 kBaddedadded
CDN Bundle (incl. Tracing, Replay)79.88 kBaddedadded
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)80.74 kBaddedadded
CDN Bundle (incl. Tracing, Replay, Feedback)85.34 kBaddedadded
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)86.22 kBaddedadded
CDN Bundle - uncompressed81.81 kBaddedadded
CDN Bundle (incl. Tracing) - uncompressed127.81 kBaddedadded
CDN Bundle (incl. Logs, Metrics) - uncompressed84.65 kBaddedadded
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed130.65 kBaddedadded
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed208.03 kBaddedadded
CDN Bundle (incl. Tracing, Replay) - uncompressed244.42 kBaddedadded
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed247.24 kBaddedadded
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed257.22 kBaddedadded
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed260.03 kBaddedadded
@sentry/nextjs (client)46.98 kBaddedadded
@sentry/sveltekit (client)42.77 kBaddedadded
@sentry/node-core52.18 kBaddedadded
@sentry/node166.36 kBaddedadded
@sentry/node - without tracing93.96 kBaddedadded
@sentry/aws-serverless109.48 kBaddedadded

Comment threadpackages/core/src/utils/spanUtils.ts
Comment threadpackages/core/src/utils/spanUtils.ts
@github-actions

github-actionsBot commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

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.

ScenarioRequests/s% of BaselinePrev. Requests/sChange %
GET Baseline9,316--added
GET With Sentry1,74919%-added
GET With Sentry (error only)6,09165%-added
POST Baseline1,199--added
POST With Sentry59149%-added
POST With Sentry (error only)1,04187%-added
MYSQL Baseline3,297--added
MYSQL With Sentry44914%-added
MYSQL With Sentry (error only)2,64280%-added

@Lms24Lms24 self-assigned this Feb 3, 2026
@Lms24
Lms24 marked this pull request as ready for review February 3, 2026 15:47

@cursorcursorBot left a comment

Copy link
Copy Markdown

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.

Comment threadpackages/core/test/lib/utils/spanUtils.test.ts
@Lms24Lms24 changed the title feat(core): Span serialization utilities (spanToV2JSON)feat(core): Add span serialization utilities (spanToV2JSON)Feb 3, 2026
Comment threadpackages/core/src/tracing/sentrySpan.ts Outdated
Comment threadpackages/core/src/utils/spanUtils.ts Outdated
@JPeer264

JPeer264 commented Feb 4, 2026

Copy link
Copy Markdown
Member

I am now a little confused if it is spanToV2JSON or spanToStreamedSpanJSON. If spanToV2Json is correct, then you can ignore my comments

@Lms24Lms24 mentioned this pull request Feb 4, 2026
20 tasks
@Lms24Lms24 changed the title feat(core): Add span serialization utilities (spanToV2JSON)feat(core): Add span serialization utilitiesFeb 4, 2026
Co-authored-by: Jan Peer Stöcklmair <jan.peer@sentry.io>
* of SDK code. If you need to get a JSON representation of a span,
* use `spanToV2JSON(span)` instead.
*/
public getStreamedSpanJSON(): StreamedSpanJSON {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To make this even more visible that this is an internal API: Should this maybe prefixed with _INTERNAL_?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Users should never interact with SentrySpan directly but leave it up to start*Span* APIs which kind of Span (as in interface) they get back or work with.

I oriented myself here primarily on the already existing getSpanJSON method. In light of keeping the name short for bundle size, I'd tend to keep it that way, unless you think we should still do it?

@Lms24

Lms24 commented Feb 4, 2026

Copy link
Copy Markdown
MemberAuthor

@JPeer264

I am now a little confused if it is spanToV2JSON or spanToStreamedSpanJSON. If spanToV2Json is correct, then you can ignore my comments

Fully understandable! I removed a bunch of the remaining v2JSON jargon.
My general thinking is:

  • whatever is (potentially) user facing, should be called "streamedSpan"
  • only internally once we generate an envelope with the final serialized spans, we use "v2", to distinguish from the pre-existing v1 span envelope.

@JPeer264

JPeer264 commented Feb 4, 2026

Copy link
Copy Markdown
Member

Not sure if a mixed jargon is helping. Especially when should we use v2 vs streaming.

However, merging this in won't harm. Internally we can always rename (it's just the muscle memory which I'm worried about)

@Lms24

Lms24 commented Feb 4, 2026

Copy link
Copy Markdown
MemberAuthor

ok you convinced me. I'll go with "streamedSpan" everywhere then. Will make some changes to this PR and open another one to adjust the envelope type names

@Lms24
Lms24 merged commit 4eeed05 into lms/feat-span-firstFeb 4, 2026
418 of 423 checks passed
@Lms24
Lms24 deleted the lms/span-first-pr7-span-serialization branch February 4, 2026 16:00
@Lms24Lms24 mentioned this pull request Feb 5, 2026
Lms24 added a commit that referenced this pull request Feb 13, 2026
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>
Lms24 added a commit that referenced this pull request Feb 16, 2026
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>
Lms24 added a commit that referenced this pull request Mar 2, 2026
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>
Lms24 added a commit that referenced this pull request Mar 4, 2026
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>
Lms24 added a commit that referenced this pull request Mar 6, 2026
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>
Lms24 added a commit that referenced this pull request Mar 9, 2026
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>
Lms24 added a commit that referenced this pull request Mar 10, 2026
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>
Lms24 added a commit that referenced this pull request Mar 13, 2026
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>
Lms24 added a commit that referenced this pull request Mar 18, 2026
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>
logaretm pushed a commit that referenced this pull request Mar 18, 2026
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>
Lms24 added a commit that referenced this pull request Mar 23, 2026
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>
Lms24 added a commit that referenced this pull request Mar 30, 2026
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>
Lms24 added a commit that referenced this pull request Apr 2, 2026
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>
Lms24 added a commit that referenced this pull request Apr 8, 2026
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>
Lms24 added a commit that referenced this pull request Apr 9, 2026
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 freeto 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

@Lms24@JPeer264@s1gr1d