Skip to content

ref(server-utils): Set error attributes on span and simplify error info extraction#21822

Merged
logaretm merged 2 commits into
developfrom
awad/align-error-attributes-in-tc
Jun 29, 2026
Merged

ref(server-utils): Set error attributes on span and simplify error info extraction#21822
logaretm merged 2 commits into
developfrom
awad/align-error-attributes-in-tc

Conversation

@logaretm

@logaretm logaretm commented Jun 26, 2026

Copy link
Copy Markdown
Member

When a traced operation throws or rejects, we now set error.type and sentry.status.message attributes on the span alongside the existing error status, so the error type lines up with the rest of our span conventions.

We talked about this yday, generally tracing channels allow us to observe more errors than before in some cases but these errors are not necessarily "unhandled", but we can still set the error attributes so our users can understand more about the op failure even if handled.

@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 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.76 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.79 kB - -
@sentry/browser (incl. Tracing, Replay) 85.25 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.84 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.95 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.61 kB - -
@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.27 kB - -
@sentry/react (incl. Tracing) 48.31 kB - -
@sentry/vue 32.66 kB - -
@sentry/vue (incl. Tracing) 47.87 kB - -
@sentry/svelte 27.5 kB - -
CDN Bundle 29.89 kB - -
CDN Bundle (incl. Tracing) 47.94 kB - -
CDN Bundle (incl. Logs, Metrics) 31.44 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.29 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.77 kB - -
CDN Bundle (incl. Tracing, Replay) 85.45 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.72 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.24 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.49 kB - -
CDN Bundle - uncompressed 88.95 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.16 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.65 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.14 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.63 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.18 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.14 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.88 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.83 kB - -
@sentry/nextjs (client) 50.7 kB - -
@sentry/sveltekit (client) 46.4 kB - -
@sentry/core/server 77.67 kB - -
@sentry/core/browser 63.97 kB - -
@sentry/node-core 61.41 kB - -
@sentry/node 122.75 kB +0.08% +91 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.39 kB -0.01% -1 B 🔽
@sentry/node - without tracing 73.13 kB -0.01% -1 B 🔽
@sentry/aws-serverless 84.02 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 180.46 kB - -
@sentry/cloudflare (withSentry) 446.48 kB - -

View base workflow run

@logaretm logaretm marked this pull request as ready for review June 26, 2026 15:02
@logaretm logaretm requested a review from a team as a code owner June 26, 2026 15:02
@logaretm logaretm requested review from a team, JPeer264, Lms24, andreiborza, mydea and s1gr1d and removed request for a team and mydea June 26, 2026 15:02

@cursor cursor Bot 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.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b802211. Configure here.

const isObject = !!error && typeof error === 'object';
const raw = isObject ? ('message' in error ? error.message : undefined) : error;

const message = raw ? String(raw) : 'unknown_error';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty Error message misclassified

Low Severity

getErrorInfo uses raw ? String(raw) : 'unknown_error', so when an Error has an empty message (e.g. new Error()), the span status and sentry.status.message become unknown_error instead of the empty string from .message, unlike the previous getErrorMessage logic and unlike nearby MySQL tracing-channel handling.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b802211. Configure here.

message,
attributes: {
[ERROR_TYPE]: type,
[SENTRY_STATUS_MESSAGE]: message,

@Lms24 Lms24 Jun 29, 2026

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.

FYI: #21811 will automatically add this attribute for anything passed to the span status message. I have no objections to setting it here implicitly though. Probably good practise to do so.

I guess the theoretical edge case here is if someone (for whatever reason) calls span.setStatus with a message after this logic ran, the logic in #21811 won't apply because the SENTRY_STATUS_MESSAGE attribute was already set. So this would omit the new status message. I'd say this is acceptable though, especially because I can't come up with a concrete use case when this would happen.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think doing it globally in your PR is better, as close to the end as possible, especially since it is a sentry attribute.

I will remove it from here!

logaretm added 2 commits June 29, 2026 09:36
…butes on span

Collapse the two branches of the thrown/rejected value handler into a single
pass that derives the status message and `error.type` once, and set
`error.type` / `sentry.status.message` attributes on the span alongside the
error status. Add assertions covering Error instances, thrown primitives,
bare error-like objects, and falsy throws.
@logaretm logaretm force-pushed the awad/align-error-attributes-in-tc branch from b802211 to eaec339 Compare June 29, 2026 13:42
const isObject = !!error && typeof error === 'object';
const raw = isObject ? ('message' in error ? error.message : undefined) : error;

const message = raw ? String(raw) : 'unknown_error';

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 falsy check in getErrorInfo incorrectly maps an Error with an empty message to 'unknown_error' instead of an empty string.
Severity: LOW

Suggested Fix

Replace the ternary operator's falsy check with a nullish coalescing operator (??) to correctly handle empty strings, which are falsy. For example: const message = raw ?? 'unknown_error';. This ensures that an empty string message is preserved.

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/server-utils/src/tracing-channel.ts#L204

Potential issue: The `getErrorInfo` function uses a falsy check (`raw ? ...`) to
determine the error message. Since an empty string (`''`) is a falsy value in
JavaScript, if an error is thrown with an empty message (e.g., `new Error('')`), its
message will be incorrectly reported as `'unknown_error'`. This is a regression from the
previous behavior which would have correctly preserved the empty string. While creating
errors with empty messages is uncommon, it is a valid edge case that could be triggered
by third-party libraries or dynamic error creation, leading to less accurate tracing
information.

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

@logaretm logaretm merged commit 438a38f into develop Jun 29, 2026
368 of 370 checks passed
@logaretm logaretm deleted the awad/align-error-attributes-in-tc branch June 29, 2026 14:34
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.

2 participants