Skip to content

Conversation

@Lms24
Copy link
Member

@Lms24 Lms24 commented Jan 30, 2026

This PR introduces span v2 types as defined in our develop spec:

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

Why the intermediate step?

SerializedSpan is annoying to deal with for users, because attributes will be converted to the {type: string, value: Value} format. So it's not ideal that users have to work with this in e.g. beforeSendSpan. We have the same problem in logs and metrics and solved it by exposing the raw attribute values to the beforeSendX callbacks and only afterwards converting them to the expected typed format.

So here's a rough overview how this will work in the upcoming captureSpan pipeline:

  1. Span ends: Span instance
  2. captureSpan converts Span instance to SpanV2JSON
  3. SpanV2JSON is used to process the span, invoke beforeSendSpan, etc.
  4. Convert SpanV2JSON to SerializedSpan
  5. enqueue SerializedSpan into buffer

Closes #19101 (added automatically)

ref #17836

Add type definitions for the new v2 span format:

- `SpanV2JSON`: JSON representation of a v2 span
- `SpanV2JSONWithSegmentRef`: SpanV2JSON with segment span reference for DSC
- `SerializedSpanContainer`: Container for serialized spans
- `SpanContainerItem`: Envelope item for span containers
- `SpanV2Envelope`: Envelope type for v2 spans
- Make `SpanLinkJSON` generic to support different attribute types
- Export `AttributeUnit` type for serialized attributes
- Add `SerializedAttribute` types for typed attribute serialization

These types form the foundation for the upcoming span streaming feature.
@github-actions
Copy link
Contributor

github-actions bot commented Jan 30, 2026

Codecov Results 📊


Generated by Codecov Action

@github-actions
Copy link
Contributor

github-actions bot commented Jan 30, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.4 kB added added
@sentry/browser - with treeshaking flags 23.85 kB added added
@sentry/browser (incl. Tracing) 42.21 kB added added
@sentry/browser (incl. Tracing, Profiling) 46.85 kB added added
@sentry/browser (incl. Tracing, Replay) 80.83 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.44 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 85.54 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 97.73 kB added added
@sentry/browser (incl. Feedback) 42.12 kB added added
@sentry/browser (incl. sendFeedback) 30.09 kB added added
@sentry/browser (incl. FeedbackAsync) 35.08 kB added added
@sentry/browser (incl. Metrics) 26.5 kB added added
@sentry/browser (incl. Logs) 26.66 kB added added
@sentry/browser (incl. Metrics & Logs) 27.32 kB added added
@sentry/react 27.13 kB added added
@sentry/react (incl. Tracing) 44.45 kB added added
@sentry/vue 29.83 kB added added
@sentry/vue (incl. Tracing) 44 kB added added
@sentry/svelte 25.41 kB added added
CDN Bundle 27.94 kB added added
CDN Bundle (incl. Tracing) 42.98 kB added added
CDN Bundle (incl. Logs, Metrics) 28.78 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 43.8 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 67.72 kB added added
CDN Bundle (incl. Tracing, Replay) 79.71 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 80.58 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 85.16 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.09 kB added added
CDN Bundle - uncompressed 81.73 kB added added
CDN Bundle (incl. Tracing) - uncompressed 127.27 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 84.56 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.1 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 207.94 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 243.87 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 246.69 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 256.67 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 259.48 kB added added
@sentry/nextjs (client) 46.8 kB added added
@sentry/sveltekit (client) 42.58 kB added added
@sentry/node-core 52.15 kB added added
@sentry/node 166.16 kB added added
@sentry/node - without tracing 93.91 kB added added
@sentry/aws-serverless 109.43 kB added added

@github-actions
Copy link
Contributor

github-actions bot commented Jan 30, 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,096 - - added
GET With Sentry 1,783 20% - added
GET With Sentry (error only) 6,235 69% - added
POST Baseline 1,223 - - added
POST With Sentry 597 49% - added
POST With Sentry (error only) 1,103 90% - added
MYSQL Baseline 3,368 - - added
MYSQL With Sentry 507 15% - added
MYSQL With Sentry (error only) 2,745 82% - added

@Lms24 Lms24 marked this pull request as draft January 30, 2026 10:53
@Lms24 Lms24 changed the title feat(core): Add SpanV2JSON and envelope type definitions feat(core/spans): Add SpanV2JSON and envelope type definitions Jan 30, 2026
@Lms24 Lms24 marked this pull request as ready for review January 30, 2026 11:19
@Lms24 Lms24 changed the title feat(core/spans): Add SpanV2JSON and envelope type definitions feat(core/spans): Add span v2 and envelope type definitions Jan 30, 2026
@Lms24 Lms24 self-assigned this Jan 30, 2026
@Lms24 Lms24 requested review from JPeer264 and s1gr1d January 30, 2026 11:20
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.

@Lms24 Lms24 mentioned this pull request Jan 30, 2026
28 tasks
@Lms24 Lms24 requested a review from andreiborza January 30, 2026 12:22
* The final, serialized span is a {@link SerializedSpan}.
* Main reason: Make it easier and safer for users to work with attributes.
*/
export interface SpanV2JSON {
Copy link
Member

Choose a reason for hiding this comment

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

l/q: Before we merge it as SpanV2JSON. Is SpanV2 the official term? Not sure how other SDKs will handle this, but maybe we could verify that before we get into future confusion what the difference between "span v2" and "span streaming" is

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I agree that SpanV2JSON is not the ideal name here 😅 SpanJSON would be ideal but that's already taken. Reusing this is IMHO not really possible because it still features properties like description, measurements, data, etc. All those properties and concepts have no place in the new v2 span protocol.

There's no official term for this intermediate step, as most SDKs besides JS never had a reason to surface serialized spans before. They just expose the regular span class instance to users. But we can't do that because OTel span instances are no longer writable at the point where they reach beforeSendSpan.

The old transaction based pattern basically was:
Span -> SpanJSON -> sent as Transaction event envelope

Now we need some other kind of intermediate name. Something like

Span -> StreamedSpanJSON -> sent as SerializedSpan array envelope

The alternative here would be to directly convert the Span to a SerializedSpan and let users deal with the complicated attribute type. This has however the consequence that they could set a type that doesn't conform with the value property of the attribute. Which is why I figured I'd prefer keeping the intermediate step.

Copy link
Member Author

Choose a reason for hiding this comment

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

The good news here is, as long as we merge against the epic branch, we can break as much as we want with the names 😅

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.

4 participants