fix(sveltekit): Avoid double-wrapping load functions#8094
Merged
Conversation
Contributor
size-limit report 📦
|
AbhiPrasad
reviewed
May 10, 2023
Comment on lines
+73
to
+76
| const patchedEvent: PatchedLoadEvent = { | ||
| ...event, | ||
| __sentry_wrapped__: true, | ||
| }; |
Contributor
There was a problem hiding this comment.
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); |
Member
Author
There was a problem hiding this comment.
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.
lforst
approved these changes
May 17, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As mentioned in the discussion in https://github.com/getsentry/sentry-javascript/pull/8083/files#r1188707540, applying the
wrap(server)?LoadWithSentrywrappers 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
canWrapLoadauto-instrumentation check to no longer bail out of auto-wrapping if Sentry code was detected.