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(tracing): Allow unsampled transactions to be findable by getTransaction() #2952

Merged
merged 5 commits into from
Oct 2, 2020

Conversation

lobsterkatie
Copy link
Member

@lobsterkatie lobsterkatie commented Oct 1, 2020

Currently, the scope.getTransaction() method relies on the presence of a span recorder in order to retrieve the currently active transaction. (This is because we assume that the transaction holding the current span on the scope (which is likely the transaction itself, but could be one of its child spans) will always be in the 0th position in the span recorder, allowing us to grab it even if the span on the scope is one of its children.)

The problem with that is that transactions with sampled = false (and all of their child spans) are missing a span recorder. (Why store all those spans if you know already you're going to ditch them?) Therefore, under the current method, they can't be found.

This PR adds a new pointer to each span, pointing at the transaction holding it. When considered as a span, the current transaction is also contained by itself, so its reference is circular. It then passes the pointer down to its children, and they to their children... you get the point. That way, every span can immediately get to its containing transaction, sampled or not.

It also changes the way getTransaction() works, to use that pointer. (It falls back to the old behavior if the new way doesn't find anything. That said, if you comment out the old behavior, removing the fallback, all tests still pass.)

As a bonus, this also fixes the bug of sampling decision not getting passed through the sentry-trace header if it happened to be false. (Because we couldn't find an unsampled transaction, it became equivalent to there being no transaction at all, and no headers were sent.)

@lobsterkatie lobsterkatie changed the title fix(tracing): All unsampled transactions to be findable by getTransaction() fix(tracing): Allow unsampled transactions to be findable by getTransaction() Oct 1, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2020

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 18.06 KB (+0.24% 🔺)
@sentry/browser - Webpack 18.88 KB (+0.3% 🔺)
@sentry/react - Webpack 18.88 KB (+0.3% 🔺)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 23.94 KB (+0.23% 🔺)

Copy link
Member

@HazAT HazAT left a comment

Choose a reason for hiding this comment

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

Good change 👍

@lobsterkatie lobsterkatie merged commit 5ac0fca into master Oct 2, 2020
@lobsterkatie lobsterkatie deleted the kmclb-fix-get-transaction branch October 2, 2020 15:54
lobsterkatie added a commit that referenced this pull request Jan 12, 2022
…4394)

In #2952, a new way of pulling the currently-active transaction off of the scope was introduced. That new way is no longer so new, and the legacy way was left in place at that time only out of an (over-)abundance of caution. It's time we removed it, both for ease of reading and for the few bytes we'll gain in bundle size reduction.
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