Skip to content

feat(core): Span serialization utilities (spanToV2JSON) #19141

@github-actions

Description

@github-actions

Note

The pull request "feat(core): Span serialization utilities (spanToV2JSON)" was created by @Lms24 but did not reference an issue. Therefore this issue was created for better visibility in external tools like Linear.

Summary

This PR adds span serialization utilities for converting spans to the V2 format, as part of the span streaming feature work.

Changes:

  • Add spanToV2JSON function to convert spans to SerializedSpan (V2 format)
  • Add getV2SpanLinks function to convert span links with serialized attributes
  • Add getV2StatusMessage function to convert status to 'ok' | 'error'
  • Rename getRootSpan implementation to INTERNAL_getSegmentSpan (with getRootSpan kept as an alias)
  • Export all new utilities from @sentry/core

Design notes:

  • spanToV2JSON checks for a getSpanV2JSON method first (which will be added to SentrySpan in a later PR), then falls back to computing the V2 JSON from the span data
  • This ensures the function works with both SentrySpan and OpenTelemetry SDK spans
  • The INTERNAL_getSegmentSpan rename prepares for future changes where "segment span" terminology is used instead of "root span"

Dependencies: PR 1 (SpanV2JSON Types) - already merged

Test plan

  • yarn lint passes
  • yarn test passes for @sentry/core
  • yarn build:dev builds successfully

Made with Cursor

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions