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(otel): Make sure we use correct hub on finish #7577

Merged
merged 3 commits into from Mar 23, 2023

Conversation

AbhiPrasad
Copy link
Member

Fixes #7538

This one was tricky to debug...

On transactions we store the hub that called hub.startTransaction(). This was because we have the assumption that the hub that calls startTransaction will be the one that finishes it.

In OpenTelemetry world this isn't the case, since our hub cloning (via domains) does not map exactly to otel context forking (via async hooks). This means async hooks might fork first, leading to the incorrect hub being used on transaction finish.

I do not want to remove the setting hub in transaction constructor, since that is needed for browser world, but to make due temporarily I added a method to override what hub is on the transaction.

The span processor then sets a new hub on finish.

@AbhiPrasad AbhiPrasad requested a review from mydea March 22, 2023 18:52
}
const scope = hub.getScope();
if (!scope) {
__DEBUG_BUILD__ && logger.error('SentrySpanProcessor has triggered onStart before a scope has been setup.');
Copy link
Member Author

Choose a reason for hiding this comment

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

We can remove all of this because a hub should always be defined (and scope is actually never used anywhere).

Copy link
Member

Choose a reason for hiding this comment

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

nice! 🔥

@github-actions
Copy link
Contributor

github-actions bot commented Mar 22, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 20.57 KB (+0.02% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 64.2 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 19.13 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 56.58 KB (+0.02% 🔺)
@sentry/browser - Webpack (gzipped + minified) 21.59 KB (+0.02% 🔺)
@sentry/browser - Webpack (minified) 71.66 KB (+0.02% 🔺)
@sentry/react - Webpack (gzipped + minified) 21.61 KB (+0.01% 🔺)
@sentry/nextjs Client - Webpack (gzipped + minified) 51.86 KB (+0.03% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 27.91 KB (+0.06% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 26.09 KB (+0.06% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 44.3 KB (+0.01% 🔺)
@sentry/replay - Webpack (gzipped + minified) 38.36 KB (0%)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 62.5 KB (+0.03% 🔺)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 56.04 KB (+0.01% 🔺)

@@ -162,6 +145,8 @@ export class SentrySpanProcessor implements OtelSpanProcessor {

if (sentrySpan instanceof Transaction) {
updateTransactionWithOtelData(sentrySpan, otelSpan);
// @ts-ignore TODO: fix this
Copy link
Member

Choose a reason for hiding this comment

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

should this still be 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.

nope, will remove!

@AbhiPrasad AbhiPrasad merged commit 1418582 into develop Mar 23, 2023
52 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-otel-span-processor-hub branch March 23, 2023 11:44
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.

Using Sentry breadcrumbs and tags alongside OpenTelemetry isn't working correctly
3 participants