Skip to content

feat(core): Make attributes required on serialized streamed spans#22053

Closed
mydea wants to merge 1 commit into
developfrom
feat/streamed-span-required-attributes
Closed

feat(core): Make attributes required on serialized streamed spans#22053
mydea wants to merge 1 commit into
developfrom
feat/streamed-span-required-attributes

Conversation

@mydea

@mydea mydea commented Jul 8, 2026

Copy link
Copy Markdown
Member

SerializedStreamedSpan.attributes (an exported type) was declared optional (attributes?: Attributes), but a serialized streamed span always carries an attributes object:

  • streamedSpanJsonToSerializedSpan() always sets attributes: serializeAttributes(...).
  • serializeAttributes() always returns an object (an empty {} at worst), never undefined.

This makes the field required so the type matches what is actually produced. Consumers can now read span.attributes[...] directly without redundant optional chaining or non-null assertions.

Only @sentry/core constructs this type; every other package consumes it read-only, so the change is safe for them — verified that the @sentry/core and @sentry/node type builds still pass.


This is the base of a stack:

`SerializedStreamedSpan.attributes` was typed as optional, but a serialized
streamed span always carries an `attributes` object: `streamedSpanJsonToSerializedSpan`
always sets `attributes: serializeAttributes(...)`, and `serializeAttributes`
always returns an object (never `undefined`).

Making the field required lets consumers read `span.attributes[...]` directly
without redundant optional chaining or non-null assertions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mydea

mydea commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

actually this is a duplicate of #22052 which is better, closing in favor of this

@mydea mydea closed this Jul 8, 2026
@mydea
mydea deleted the feat/streamed-span-required-attributes branch July 8, 2026 09:05
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