Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(opentelemetry): Do not stomp span status when startSpan callback throws #11170

Merged
merged 2 commits into from Mar 25, 2024

Conversation

lforst
Copy link
Member

@lforst lforst commented Mar 18, 2024

This PR fixes span status stomping in the Otel starSpan and startSpanManual implementations.

When the callbacks threw, we didn't check whether there was already a more useful status on there and just stomped it with an ERROR status. Now we only set the status to ERROR when it wasn't defined already.

Comment on lines +89 to +91
// Note: Because of this, we currently have a circular type dependency (which we opted out of in package.json).
// This is not avoidable as we need `spanToJSON` in `spanUtils.ts`, which in turn is needed by `span.ts` for backwards compatibility.
// And `spanToJSON` needs the Span class from `span.ts` to check here.
Copy link
Member Author

Choose a reason for hiding this comment

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

I stumbled onto this but found that this comment had no place in JSDoc.

Copy link
Member

Choose a reason for hiding this comment

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

Note that all fields returned here are optional and need to be guarded against.

I'd argue this might still be a helpful message but the types should hint that anyway.
Also just to double-check: Putting a line comment between the JSDoc block and the function declaration doesn't prevent the JSDoc from being associated with the function, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep the JSdoc still works!

Copy link
Contributor

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) 80.74 KB (added)
@sentry/browser (incl. Tracing, Replay) 72.1 KB (added)
@sentry/browser (incl. Tracing, Replay with Canvas) 75.9 KB (added)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 65.66 KB (added)
@sentry/browser (incl. Tracing) 36.7 KB (added)
@sentry/browser (incl. browserTracingIntegration) 36.7 KB (added)
@sentry/browser (incl. feedbackIntegration) 31.36 KB (added)
@sentry/browser (incl. feedbackModalIntegration) 31.48 KB (added)
@sentry/browser (incl. feedbackScreenshotIntegration) 31.49 KB (added)
@sentry/browser (incl. sendFeedback) 27.45 KB (added)
@sentry/browser 22.62 KB (added)
CDN Bundle (incl. Tracing, Replay, Feedback) 75.08 KB (added)
CDN Bundle (incl. Tracing, Replay) 69.92 KB (added)
CDN Bundle (incl. Tracing) 36.28 KB (added)
CDN Bundle 23.99 KB (added)
CDN Bundle (incl. Tracing, Replay) - uncompressed 219.62 KB (added)
CDN Bundle (incl. Tracing) - uncompressed 109.56 KB (added)
CDN Bundle - uncompressed 71.09 KB (added)
@sentry/react (incl. Tracing, Replay) 72.09 KB (added)
@sentry/react 22.64 KB (added)

@lforst lforst requested review from Lms24 and AbhiPrasad March 18, 2024 16:29
@lforst
Copy link
Member Author

lforst commented Mar 19, 2024

I will not merge this yet. I'd like to add tests but I had trouble writing some that verified the behaviour I want here...

@lforst
Copy link
Member Author

lforst commented Mar 25, 2024

Mergin to unblock #11016

This is implicitly covered by Next.js tests

@lforst lforst merged commit 284e90d into develop Mar 25, 2024
92 checks passed
@lforst lforst deleted the lforst-fix-span-status branch March 25, 2024 13:25
cadesalaberry pushed a commit to cadesalaberry/sentry-javascript that referenced this pull request Apr 19, 2024
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.

None yet

2 participants