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(sveltekit): Avoid double-wrapping load functions #8094

Merged
merged 2 commits into from May 17, 2023

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented May 10, 2023

As mentioned in the discussion in https://github.com/getsentry/sentry-javascript/pull/8083/files#r1188707540, applying the wrap(server)?LoadWithSentry wrappers multiple times shouldn't lead to double wrapping but instead we should detect if we already wrapped a load function and no-op in this case. This PR patches the respective load events with a flag to detect double wrapping.

Double wrapping can occur, for instance, if users already applied the load wrapper function to their code but also use auto-wrapping. With this change, we'll still apply the wrapper twice but the second wrapper will simply no-op.

Once this is merged, we can adjust the canWrapLoad auto-instrumentation check to no longer bail out of auto-wrapping if Sentry code was detected.

@Lms24 Lms24 requested review from a team, stephanie-anderson, AbhiPrasad and lforst and removed request for a team May 10, 2023 11:00
@Lms24 Lms24 self-assigned this May 10, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 10, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 21.02 KB (0%)
@sentry/browser - ES5 CDN Bundle (minified) 65.62 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 19.56 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified) 58.09 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 21.17 KB (0%)
@sentry/browser - Webpack (minified) 69.04 KB (0%)
@sentry/react - Webpack (gzipped + minified) 21.19 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 49.11 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 28.64 KB (0%)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 26.88 KB (0%)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 47.62 KB (0%)
@sentry/replay - Webpack (gzipped + minified) 41.46 KB (0%)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 66.51 KB (0%)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 59.38 KB (0%)

Comment on lines 73 to 76
const patchedEvent: PatchedLoadEvent = {
...event,
__sentry_wrapped__: true,
};
Copy link
Member

Choose a reason for hiding this comment

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

h: Can we use addNonEnumerableProperty and mutate the original event? This way we can just do wrappingTarget.apply(thisArg, args) like before, which is more safe if more args are added in the future.

Suggested change
const patchedEvent: PatchedLoadEvent = {
...event,
__sentry_wrapped__: true,
};
addNonEnumerableProperty(event, '__sentry_wrapped__', true);

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 we can do that easily for the server-side, good call! On the client side, we have to patch the event for the fetch instrumentation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 1d1dd92

@Lms24 Lms24 merged commit e52847e into develop May 17, 2023
32 checks passed
@Lms24 Lms24 deleted the lms/sveltekit-wrapLoad-check-double-wrap branch May 17, 2023 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants