fix(sveltekit): Resolve @opentelemetry/api via the SDK on SvelteKit 3 - #24736
Merged
Merged
Conversation
SvelteKit 3.0.0-next.28 externalizes `@opentelemetry/api` in server builds, so the Kit runtime imports it at runtime from the app root. Under pnpm or Yarn PnP that only resolves if the app depends on it directly, so enabling `tracing.server` made every request fail. The `sentrySvelteKit()` plugin now redirects that import to a new `@sentry/sveltekit/opentelemetry-api` re-export. It resolves because the app always depends on the SDK directly, and it stays external, so the Kit runtime and `instrumentation.server.js` still share one instance. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
size-limit report 📦
|
Lms24
marked this pull request as ready for review
September 25, 2026 11:05
Lms24
requested review from
andreiborza,
chargome and
nicohrubec
and removed request for
a team
September 25, 2026 11:05
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.
Since
@sveltejs/kit@next.28, PR sveltejs/kit#17081,@opentelemetry/apiis externalized from the sveltekit server build. Thus the dynamic import of@opentelemetry/apiremains untouched during build, meaning the API package is now a required dependency module during runtime. This is technically correct and fine for anyone using a default OTel setup, where users would install@opentelemetry/apianyway.However, for Sentry users,
@opentelemetry/apiis a transitive dependency of@sentry/node, so not a direct app dependency. When users usepnpmor Yarnpnp, dynamic imports can only resolve direct dependencies and not transitive deps. This broke our e2e tests.To avoid having to make the Sentry SDK more complicated by instructing users to manually install
@opentelemetry/api, this PR adds a bit of a "redirection workaround" to our package, to get the dynamic import working again without user intervention:This PR:
@opentelemetry/apias a dep of@sentry/sveltekit@opentelemetry/apifrom Sveltekit SDK package as subpath export@opentelemetry/apiAnd point Vite to our subpath export instead.Kit 3 E2E tests pass again with this fix.
Caveat: This redirection always applies, so if users actively installed both
@sentry/sveltekitand@opentelemetry/api, our Vite plugin now always redirects the import to our version of the OTel API package. If this causes problems, we can revisit the fix and offer an opt out possibility of the redirection for example.