Skip to content

fix(core): Serialize streamed span status message to sentry.status.message attribute#21811

Open
Lms24 wants to merge 3 commits into
developfrom
lms/fix-core-streaming-span-status-message
Open

fix(core): Serialize streamed span status message to sentry.status.message attribute#21811
Lms24 wants to merge 3 commits into
developfrom
lms/fix-core-streaming-span-status-message

Conversation

@Lms24

@Lms24 Lms24 commented Jun 26, 2026

Copy link
Copy Markdown
Member

Fixes a semi-deliberate oversight (lol) from my end that caused span status messages to be discarded when creating a StreamedSpanJSON from a Span instance. The deliberate part was to get rid of complicated statuses overall. The oversight was that there's a good use case to augment an error status span with a message: We sometimes want to record that an operation tracked by a span errored but explicitly not capture an error for it (since users likely try/catch said operation). Classic example is Connection Refused for databases.

closes #21800

@Lms24 Lms24 marked this pull request as draft June 26, 2026 10:03
@Lms24 Lms24 changed the title fix(core): Serialize streamed span status message to sentry.status.message attribute feat(core): Serialize streamed span status message to sentry.status.message attribute Jun 26, 2026
@Lms24 Lms24 force-pushed the lms/fix-core-streaming-span-status-message branch from fbab8c3 to c18bd3e Compare June 26, 2026 10:15
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 27.48 kB - -
@sentry/browser - with treeshaking flags 25.91 kB - -
@sentry/browser (incl. Tracing) 46.03 kB +0.14% +62 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 47.77 kB +0.11% +50 B 🔺
@sentry/browser (incl. Tracing, Profiling) 50.79 kB +0.08% +38 B 🔺
@sentry/browser (incl. Tracing, Replay) 85.27 kB +0.06% +49 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.87 kB +0.08% +58 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 89.96 kB +0.06% +47 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 102.61 kB +0.05% +44 B 🔺
@sentry/browser (incl. Feedback) 44.66 kB - -
@sentry/browser (incl. sendFeedback) 32.26 kB - -
@sentry/browser (incl. FeedbackAsync) 37.4 kB - -
@sentry/browser (incl. Metrics) 28.54 kB - -
@sentry/browser (incl. Logs) 28.78 kB - -
@sentry/browser (incl. Metrics & Logs) 29.47 kB - -
@sentry/react 29.28 kB +0.01% +1 B 🔺
@sentry/react (incl. Tracing) 48.33 kB +0.11% +50 B 🔺
@sentry/vue 32.66 kB +0.13% +40 B 🔺
@sentry/vue (incl. Tracing) 47.9 kB +0.14% +63 B 🔺
@sentry/svelte 27.5 kB - -
CDN Bundle 29.89 kB - -
CDN Bundle (incl. Tracing) 47.93 kB +0.1% +44 B 🔺
CDN Bundle (incl. Logs, Metrics) 31.44 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.28 kB +0.1% +47 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 70.78 kB - -
CDN Bundle (incl. Tracing, Replay) 85.44 kB +0.06% +45 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.73 kB +0.06% +48 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 91.25 kB +0.07% +57 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.49 kB +0.05% +42 B 🔺
CDN Bundle - uncompressed 88.94 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.16 kB +0.1% +131 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.65 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.13 kB +0.09% +131 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.62 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.18 kB +0.05% +131 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.13 kB +0.05% +131 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.88 kB +0.05% +131 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.82 kB +0.05% +131 B 🔺
@sentry/nextjs (client) 50.71 kB +0.09% +45 B 🔺
@sentry/sveltekit (client) 46.41 kB +0.11% +48 B 🔺
@sentry/core/server 77.61 kB +0.1% +74 B 🔺
@sentry/core/browser 63.95 kB +0.11% +67 B 🔺
@sentry/node-core 61.55 kB +0.07% +40 B 🔺
@sentry/node 123.54 kB +0.05% +56 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.45 kB +0.1% +47 B 🔺
@sentry/node - without tracing 73.68 kB +0.1% +67 B 🔺
@sentry/aws-serverless 84.47 kB +0.08% +63 B 🔺
@sentry/cloudflare (withSentry) - minified 180.47 kB +0.09% +162 B 🔺
@sentry/cloudflare (withSentry) 446.69 kB +0.11% +457 B 🔺

View base workflow run

@Lms24 Lms24 changed the title feat(core): Serialize streamed span status message to sentry.status.message attribute fix(core): Serialize streamed span status message to sentry.status.message attribute Jun 26, 2026
@Lms24 Lms24 marked this pull request as ready for review June 26, 2026 14:55
@Lms24 Lms24 requested review from a team as code owners June 26, 2026 14:55
@Lms24 Lms24 requested review from JPeer264, andreiborza, logaretm, mydea and s1gr1d and removed request for a team, JPeer264 and andreiborza June 26, 2026 14:55
@Lms24 Lms24 self-assigned this Jun 26, 2026
Comment on lines +355 to +359
const statusMessage = getSimpleStatus(status) === 'error' ? status?.message : undefined;
return {
...(statusMessage && { [SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]: statusMessage }),
...attributes,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The addStatusMessageAttribute function always creates a new object, which contradicts its documentation comment stating the original reference would be returned.
Severity: LOW

Suggested Fix

Modify addStatusMessageAttribute to check if a statusMessage exists. If it does not, return the original attributes object directly. Otherwise, proceed with creating and returning a new object with the added attribute.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/core/src/utils/spanUtils.ts#L355-L359

Potential issue: The function `addStatusMessageAttribute` in `spanUtils.ts` has a
comment stating that it will return the original `attributes` object reference untouched
if no status message is added. However, the implementation always creates a new object
via spread syntax (`{ ...attributes }`), even when no message is present. While this
does not cause a functional bug as no downstream code relies on reference equality, it
creates a minor inefficiency by allocating a new object unnecessarily and makes the
code's behavior inconsistent with its documentation.

Did we get this right? 👍 / 👎 to inform future reviews.

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.

Handle span status message on streamed spans

1 participant