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(core): Fix scope capturing via captureContext function (#10735) #10737

Merged
merged 2 commits into from
Feb 20, 2024

Conversation

mydea
Copy link
Member

@mydea mydea commented Feb 20, 2024

Backport to v7.

In #9801, we introduced a regression that if you pass a function as captureContext to capture methods, the returned scope is not used.

The cause for this was a confusion on my end, based on the slightly weird way this works in scope.update(fn) - we don't actually merge this or update the scope based on the return value of fn, but fn receives the scope as argument, does nothing with the return type of fn and just returns it - which we didn't use, because I assumed that scope.update would actually return the scope (also, the return type of it is this which is not correct there).

This PR changes this so that the returned scope of fn is actually merged with the scope, same as if you'd pass a scope directly - so this is fundamentally the same now:

const otherScope = new Scope();
scope.update(otherScope);
scope.update(() => otherScope);

(which before would have had vastly different outcomes!)

I added a bunch of tests to verify how this works/should work.

Fixes #10686

In #9801, we
introduced a regression that if you pass a function as `captureContext`
to capture methods, the returned scope is not used.

The cause for this was a confusion on my end, based on the slightly
weird way this works in `scope.update(fn)` - we don't actually merge
this or update the scope based on the return value of `fn`, but `fn`
receives the `scope` as argument, does nothing with the return type of
`fn` and just returns it - which we didn't use, because I assumed that
`scope.update` would actually return the scope (also, the return type of
it is `this` which is not correct there).

This PR changes this so that the returned scope of `fn` is actually
merged with the scope, same as if you'd pass a `scope` directly - so
this is fundamentally the same now:

```js
const otherScope = new Scope();
scope.update(otherScope);
scope.update(() => otherScope);
```

(which before would have had vastly different outcomes!)

I added a bunch of tests to verify how this works/should work.

Fixes #10686
@mydea mydea requested a review from lforst February 20, 2024 09:22
@mydea mydea self-assigned this Feb 20, 2024
Copy link
Contributor

github-actions bot commented Feb 20, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 78.43 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 69.66 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay with Canvas) - Webpack (gzipped) 73.6 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 63.28 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 33.62 KB (+0.06% 🔺)
@sentry/browser (incl. browserTracingIntegration) - Webpack (gzipped) 33.5 KB (+0.06% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 31.38 KB (+0.04% 🔺)
@sentry/browser (incl. sendFeedback) - Webpack (gzipped) 31.39 KB (+0.04% 🔺)
@sentry/browser - Webpack (gzipped) 22.66 KB (+0.11% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 76.72 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 68.21 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 34.03 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 25.04 KB (+0.14% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 214.99 KB (+0.07% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 102.78 KB (+0.14% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 75.08 KB (+0.19% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 37.19 KB (+0.08% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 70.03 KB (+0.03% 🔺)
@sentry/react - Webpack (gzipped) 22.69 KB (+0.1% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 87.7 KB (+0.03% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 51.89 KB (+0.04% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 17.24 KB (+0.12% 🔺)

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