Skip to content

fix(opentelemetry): Do not stomp span error status #11169

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

Merged
merged 2 commits into from
Mar 19, 2024

Conversation

lforst
Copy link
Contributor

@lforst lforst commented Mar 18, 2024

This fixes a bug I noticed when attempting to port the Next.js SDK to OTEL.

The behaviour of mapStatus() (which is called when we serialize spans & transactions to set the span and transaction status) previously always looked at the HTTP and GRPC status attributes first when determining the status of a span, stomping any previously set status in the process. Additionally, and arguably worse, when there was no HTTP and GRPC status attribute on the span, and the span status was ERROR, we completely stomped the error message with unknown_error.

This PR changes the implementation so that we first prefer the status code that is already set on the span when it is OK and ERROR, otherwise we try to infer the span status from the HTTP and GRPC codes, we default to setting the span status to OK when the otel span status is UNSET, and we default to ERROR when we see an unknown otel span status.

Copy link
Contributor

github-actions bot commented Mar 18, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) 80.75 KB (added)
@sentry/browser (incl. Tracing, Replay) 72.11 KB (added)
@sentry/browser (incl. Tracing, Replay with Canvas) 75.91 KB (added)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 65.66 KB (added)
@sentry/browser (incl. Tracing) 36.71 KB (added)
@sentry/browser (incl. browserTracingIntegration) 36.71 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.09 KB (added)
CDN Bundle (incl. Tracing, Replay) 69.93 KB (added)
CDN Bundle (incl. Tracing) 36.29 KB (added)
CDN Bundle 23.99 KB (added)
CDN Bundle (incl. Tracing, Replay) - uncompressed 219.67 KB (added)
CDN Bundle (incl. Tracing) - uncompressed 109.61 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, AbhiPrasad and s1gr1d March 19, 2024 08:50
@@ -10,6 +10,7 @@ export const SPAN_STATUS_ERROR = 2;
* @param httpStatus The HTTP response status code.
* @returns The span status or unknown_error.
*/
// https://develop.sentry.dev/sdk/event-payloads/span/
Copy link
Member

Choose a reason for hiding this comment

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

l (feel free to ignore): Any reason for not adding this link directly to the JSDoc header?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am a bit cautious with links in js doc bc they might become stale. If it's just in our codebase it's not that bad but as a user it's frustrating if links are dead.

Copy link
Member

Choose a reason for hiding this comment

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

Ok fair point, in this case I think it's totally fine. In other cases I think it's still worth to take that risk but admittedly, I didn't think too much about it until now 😅

const statusCode = status && status.code;
if (statusCode === SpanStatusCode.OK || statusCode === SpanStatusCode.UNSET) {
return { code: SPAN_STATUS_OK };
if (typeof grpcCodeAttribute === 'string') {
Copy link
Member

Choose a reason for hiding this comment

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

m: can grpcCodeAttribute be of any other type than string like httpCodeAttribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opened an issue to track this, as I didn't touch that particular logic: #11195

It may very well be that this is a leftover from our first initial OTEL implementation draft.

@lforst lforst merged commit 125b368 into develop Mar 19, 2024
@lforst lforst deleted the lforst-fix-span-status-handling-1 branch March 19, 2024 09:39
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.

2 participants