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

feat(core): Deprecate trace in favor of startSpan #10012

Merged
merged 3 commits into from
Jan 4, 2024
Merged

feat(core): Deprecate trace in favor of startSpan #10012

merged 3 commits into from
Jan 4, 2024

Conversation

mydea
Copy link
Member

@mydea mydea commented Jan 2, 2024

Also add a handleCallbackErrors utility to replace this.

We've been using this in a few places, and since it has a bit of a different usage than startSpan I had to add a new utility to properly make this work. The upside is that we now can ensure to use the same implementation for this "maybe promise" handling everywhere!

@mydea mydea requested review from lforst, Lms24 and AbhiPrasad January 2, 2024 15:02
@mydea mydea self-assigned this Jan 2, 2024
() => callback(activeSpan),
() => {
// Only update the span status if it hasn't been changed yet
if (activeSpan && (!activeSpan.status || activeSpan.status === 'ok')) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Small adjustment here as well to make sure we don't overwrite the span status if it was set to something else before.

() => callback(activeSpan),
() => {
// Only update the span status if it hasn't been changed yet
if (activeSpan && (!activeSpan.status || activeSpan.status === 'ok')) {
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if startSpan should concern itself with the span status. I believe the OTEL equivalent primitive also doesn't do this.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, this is a "feature" that we do that automatically. Otherwise users would need to do that themselves all the time 🤔 no strong feelings, but this is what the startSpan API is supposed to do afaik cc @AbhiPrasad

Copy link
Member

Choose a reason for hiding this comment

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

given we are also an error monitoring SDK, I think it makes sense to set error status where appropriate, I think this bit of DX is useful for people.

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

github-actions bot commented Jan 2, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 76.07 KB (0%)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 67.46 KB (0%)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 61.07 KB (0%)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 32.04 KB (0%)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 30.46 KB (0%)
@sentry/browser - Webpack (gzipped) 22.17 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 73.49 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 65.16 KB (+0.04% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 31.33 KB (+0.11% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 23.25 KB (+0.11% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 204.24 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 94.13 KB (+0.06% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 68.99 KB (+0.08% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 34.3 KB (+0.1% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 67.87 KB (0%)
@sentry/react - Webpack (gzipped) 22.19 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 84.49 KB (0%)
@sentry/nextjs Client - Webpack (gzipped) 49.1 KB (0%)
@sentry-internal/feedback - Webpack (gzipped) 16.69 KB (0%)

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -28,7 +28,7 @@ export function withEdgeWrapping<H extends EdgeRouteHandler>(
baggage,
});

return trace(
return startSpan(
Copy link
Member Author

Choose a reason for hiding this comment

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

@lforst can you especially check that the logic for the next js spans is still correct? Just to be sure 😅

Copy link
Member

Choose a reason for hiding this comment

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

It looks like we didn't wrap this apply call in handleCallbackErrors:

const res = originalFunction.apply(thisArg, args);

Copy link
Member Author

Choose a reason for hiding this comment

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

ah yeah, forgot about this - initially wrote this to just use try-catch but safer to use the util here too 👍

mydea added 2 commits January 3, 2024 14:33
Also add a `handleCallbackErrors` utility to replace this.

if (isThenable(maybePromiseResult)) {
// @ts-expect-error - the isThenable check returns the "wrong" type here
return maybePromiseResult.then(
Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I see some nextjs E2E tests are failing - can it be that this was "swallowed" before due to this (which we changed for startSpan but I think not for trace? 🤔 cc @Lms24 / @lforst

Copy link
Member

Choose a reason for hiding this comment

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

I think the failures might be legit. I don't think there was anything being swallowed. It seems like we're timing out on waiting for elements to appear on screen. Can you verify that you are returning all the values and not stalling anything? Are we returning the response here? https://github.com/getsentry/sentry-javascript/pull/10012/files#diff-6a177c0f974e405d7e55f4d0155181376d92b37749269c0904cdc6e94b17ef84L97

Copy link
Member

Choose a reason for hiding this comment

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

I added it back. Let's see.

Copy link
Member Author

Choose a reason for hiding this comment

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

OMG. good tests!

Copy link
Member

Choose a reason for hiding this comment

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

Seems like an oversight a linter should have caught...

Copy link
Member

Choose a reason for hiding this comment

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

Re added the lint rule here #10049

@mydea mydea merged commit a696aef into develop Jan 4, 2024
95 checks passed
@mydea mydea deleted the fn/trace branch January 4, 2024 10: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.

4 participants