feat(sveltekit): Auto-instrument universal and server load
functions
#7969
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.
This PR adds auto-wrapping of
load
functions inpage(.server).(ts|js)
files to the SvelteKit SDK.API
API wise, this is not a breaking change for users, as internally, we just add an additional plugin which is returned by the
sentrySvelteKit
plugin factory function. However, users can add new options to the factory functions, to control auto-wrapping:Methodology
After trying a lot of options to bundle the original page module with a Sentry wrapper template (i.e. proxy loader in NextJS), I pivoted to modify the AST directly. The reason is that every time we touched source map generation, the resulting server source maps would no longer point to the original +page.ts/js files, causing broken source maps.
I believe this is a bug in the SvelteKit build process but I didn't find a way to work around this. Therefore, I suggest we go with the AST-based approach for now and revisit later if necessary.
I'm not too happy with the current approach because the fact that we can't touch the source maps also means, our AST wrapping can't modify the file content arbitrarily. We have to preserve the original location (at least the line) where the declaration of the
load
function was.This PR also adds various tests for different kinds of
load
exports to ensure we handle them correctly.closes #7940