Skip to content

fix(sveltekit): Support browser tracing with SvelteKit 3#22264

Draft
Lms24 wants to merge 5 commits into
developfrom
feat/sveltekit-3-compat-investigation
Draft

fix(sveltekit): Support browser tracing with SvelteKit 3#22264
Lms24 wants to merge 5 commits into
developfrom
feat/sveltekit-3-compat-investigation

Conversation

@Lms24

@Lms24 Lms24 commented Jul 14, 2026

Copy link
Copy Markdown
Member

⚠️ This is mostly unreviewed slop. Used it as a base to try some approaches. Let's not merge this before a careful review or close it in favour of a better approach.

Support SvelteKit 3 browser tracing without changing existing SDK setup. The integration selects $app/stores for SvelteKit 2 and $app/state for SvelteKit 3, using rune-based navigation observation for the latter. A preview E2E app verifies client startup, pageload tracing, and navigation tracing while existing SvelteKit 2 coverage guards compatibility.

Breaking changes: None. The public API and configuration remain unchanged; the peer range is only widened to accept SvelteKit 3.

Fixes #22263

chargome added a commit that referenced this pull request Jul 15, 2026
SvelteKit 3.0.0-next.8 promoted native tracing config out of `experimental`
(`kit.experimental.tracing` -> `kit.tracing`) and dropped the
`experimental.instrumentation` flag, which broke the app build. Migrate the
Vite config to the new API.

Client-side capture is also broken on next.8 because the SDK's browser
integration imports `$app/stores`, which now throws at runtime (removed in
favour of `$app/state`), so the app never hydrates. Skip the client-side
tests until SvelteKit 3 browser support lands (#22264); server-side tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chargome chargome self-assigned this Jul 15, 2026
@chargome chargome force-pushed the feat/sveltekit-3-compat-investigation branch from df225dd to 1ca9e2e Compare July 15, 2026 14:40
chargome and others added 5 commits July 15, 2026 16:42
…nfig

SvelteKit 3.0.0-next.8 promoted the native server-tracing config out of
`experimental` (`kit.experimental.tracing.server` -> `kit.tracing.server`).
Read both locations when detecting native tracing so the SDK works across the
supported peer range (SvelteKit 2.31+ and early Kit 3 prereleases keep it under
`experimental`). Applies to detection from both the Vite plugin `api.options`
and `svelte.config.js`, and covers both shapes in the unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Select the compatible tracing state API at runtime so existing setups
continue to work across SvelteKit 2 and 3. Add preview coverage for
pageload and navigation tracing without the removed $app/stores module.

Fixes #22263
Co-Authored-By: Cursor <cursoragent@cursor.com>

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment on lines +37 to +42
if (IS_SVELTEKIT_3) {
void import('./kit3BrowserTracingIntegration').then(({ instrumentSvelteKit3Tracing }) => {
instrumentSvelteKit3Tracing(client, options);
});
} else {
void _instrumentSvelteKit2Tracing(client, options);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I kinda don't like the dynamic import here because:

  • parts of the SDK will be duplicated in the lazily loaded bundle
  • timing-wise, we start our instrumentation later than the original, eagerly imported integration.

Maybe the way forward is to instruct users to switch to a new version of the integration that imports eagerly from $app/state

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

see comment

@chargome chargome force-pushed the feat/sveltekit-3-compat-investigation branch from 1ca9e2e to 8b95aff Compare July 15, 2026 14:57
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.

$app/storeswill be deprecated in SvelteKit 3 (crashing already in prerelease)

2 participants