Skip to content

fix(sveltekit): Resolve @opentelemetry/api via the SDK on SvelteKit 3 - #24736

Merged
Lms24 merged 1 commit into
developfrom
fix/sveltekit-otel-api-alias
Sep 25, 2026
Merged

Lms24 merged 1 commit into
developfrom
fix/sveltekit-otel-api-alias

Conversation

@Lms24

@Lms24 Lms24 commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Since @sveltejs/kit@next.28, PR sveltejs/kit#17081, @opentelemetry/api is externalized from the sveltekit server build. Thus the dynamic import of @opentelemetry/api remains 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/api anyway.

However, for Sentry users, @opentelemetry/api is a transitive dependency of @sentry/node, so not a direct app dependency. When users use pnpm or Yarn pnp, 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:

  • Adds @opentelemetry/api as a dep of @sentry/sveltekit
  • Exports @opentelemetry/api from Sveltekit SDK package as subpath export
  • Adds a vite plugin to redirect id resolving of @opentelemetry/api And 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/sveltekit and @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.

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>
@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.24 kB - -
@sentry/browser - with treeshaking flags 27.5 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.4 kB - -
@sentry/browser (incl. Tracing) 51.15 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 51.17 kB - -
@sentry/browser (incl. Tracing, Profiling) 54.18 kB - -
@sentry/browser (incl. Tracing, Replay) 90.76 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.86 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 95.46 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 108.41 kB - -
@sentry/browser (incl. Feedback) 46.76 kB - -
@sentry/browser (incl. sendFeedback) 34.3 kB - -
@sentry/browser (incl. FeedbackAsync) 39.41 kB - -
@sentry/browser (incl. Metrics) 30.25 kB - -
@sentry/browser (incl. Logs) 30.51 kB - -
@sentry/browser (incl. Metrics & Logs) 31.18 kB - -
@sentry/react 31 kB - -
@sentry/react (incl. Tracing) 53.45 kB - -
@sentry/vue 36.74 kB - -
@sentry/vue (incl. Tracing) 53.7 kB - -
@sentry/svelte 29.26 kB - -
CDN Bundle 30.93 kB - -
CDN Bundle (incl. Tracing) 51.69 kB - -
CDN Bundle (incl. Logs, Metrics) 33.2 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.66 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.92 kB - -
CDN Bundle (incl. Tracing, Replay) 89.28 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.25 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 95.45 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 97.42 kB - -
CDN Bundle - uncompressed 91.4 kB - -
CDN Bundle (incl. Tracing) - uncompressed 153.77 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.97 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 159.73 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.54 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 273.5 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 279.44 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 287.2 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 293.13 kB - -
@sentry/nextjs (client) 55.77 kB - -
@sentry/sveltekit (client) 51.59 kB - -
@sentry/core/server 39.95 kB - -
@sentry/core/browser 13.63 kB - -
@sentry/node 133.9 kB +0.01% +6 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.43 kB - -
@sentry/node - without tracing 90.46 kB +0.02% +14 B 🔺
@sentry/node - without channel injection 112.41 kB +0.01% +10 B 🔺
@sentry/aws-serverless 98.72 kB +0.01% +5 B 🔺
@sentry/cloudflare (withSentry) - minified 206.49 kB - -
@sentry/cloudflare (withSentry) 513.73 kB - -

View base workflow run

@Lms24 Lms24 self-assigned this Sep 25, 2026
@Lms24
Lms24 marked this pull request as ready for review September 25, 2026 11:05
@Lms24
Lms24 requested a review from a team as a code owner September 25, 2026 11:05
@Lms24
Lms24 requested review from andreiborza, chargome and nicohrubec and removed request for a team September 25, 2026 11:05

@andreiborza andreiborza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wild :)

@Lms24
Lms24 merged commit 2a58c97 into develop Sep 25, 2026
52 checks passed
@Lms24
Lms24 deleted the fix/sveltekit-otel-api-alias branch September 25, 2026 11:18
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.

2 participants