Skip to content

fix(tracing): Attach request instrumentation span to active span instead of current transaction#6778

Merged
lforst merged 3 commits intomasterfrom
lforst-attach-request-spans-to-current-span
Jan 16, 2023
Merged

fix(tracing): Attach request instrumentation span to active span instead of current transaction#6778
lforst merged 3 commits intomasterfrom
lforst-attach-request-spans-to-current-span

Conversation

@lforst
Copy link
Copy Markdown
Contributor

@lforst lforst commented Jan 16, 2023

Currently, the request instrumentation (fetch & XHR) doesn't attach spans to the currently active span on the scope but always on the active transaction.

While trying to instrument fetch for wintercg runtimes I ran into the issue that even when we intentionally set the span on the scope, fetch spans would still end up on the transaction. This PR would fix this behavior by attaching the fetch/xhr span to the currently active span instead.

@lforst lforst requested a review from AbhiPrasad January 16, 2023 09:10
@lforst lforst self-assigned this Jan 16, 2023
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 16, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.84 KB (-0.01% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 61.46 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.61 KB (+0.01% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 55 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 20.37 KB (0%)
@sentry/browser - Webpack (minified) 66.54 KB (0%)
@sentry/react - Webpack (gzipped + minified) 20.4 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.67 KB (+0.08% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.83 KB (+0.07% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.28 KB (+0.14% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 43.35 KB (-0.84% 🔽)
@sentry/replay - Webpack (gzipped + minified) 38.58 KB (-0.97% 🔽)

Comment on lines +190 to +192
const currentScope = getCurrentHub().getScope();
const currentSpan = currentScope ? currentScope.getSpan() : undefined;
const activeTransaction = currentSpan ? currentSpan.transaction : undefined;
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.

Suggested change
const currentScope = getCurrentHub().getScope();
const currentSpan = currentScope ? currentScope.getSpan() : undefined;
const activeTransaction = currentSpan ? currentSpan.transaction : undefined;
const currentScope = getCurrentHub().getScope();
const currentSpan = currentScope && currentScope.getSpan();
const activeTransaction = currentSpan && currentSpan.transaction;

Ditto with the logic below.

@lforst lforst merged commit ed136de into master Jan 16, 2023
@lforst lforst deleted the lforst-attach-request-spans-to-current-span branch January 16, 2023 12:09
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