Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OpenTelemetry Instrumentation in SvelteKit SDK #14986

Open
5 tasks
Lms24 opened this issue Jan 13, 2025 · 0 comments
Open
5 tasks

Support OpenTelemetry Instrumentation in SvelteKit SDK #14986

Lms24 opened this issue Jan 13, 2025 · 0 comments
Labels
Package: sveltekit Issues related to the Sentry SvelteKit SDK

Comments

@Lms24
Copy link
Member

Lms24 commented Jan 13, 2025

Problem Statement

As of today, server-side OpenTelemetry-backed instrumentation does not correctly work in our @sentry/sveltekit SDK. This is caused by us initializing the SDK in hooks.server.ts; a file that is imported fairly at the beginning of the SvelteKit server app lifecycle. However, given the ESM nature of SvelteKit, the SDK initialization still needs to happen earlier.

As of today:

  • No Otel-based instrumentation works (e.g. DB spans)
  • Users get http.server spans from our own instrumentation (via the sentryHandle request handler)
  • Users get spans for load functions via our build time auto instrumentation.
  • Users get http.client spans, due to Undici fetch using diagnostics channels
  • Request isolation works due to our instrumentation creating an isolation scope

Solution Brainstorm

There are two (three) ways we can achieve an early enough initialization so that Otel-based instrumentation works:

  • making users --import an SDK initialization file like in our Node SDK. This will work for the Node adapter but not in envs like Vercel where you can't specify --import.
  • adding native support for instrumentation to SvelteKit and its adapters, like NextJS does with its instrumentation.ts file. I took a stab at this over the holidays and got first results. This will require coordination with the svelte team but I believe it's the only fully sustainable way of ensuring a proper instrumentation architecture that will work on all platforms.
  • [haven't thought this through] perhaps we can hack a dynamic import of the server app into the SvelteKit build which means that we first import our SDK init code and then dynamically import the server app code. It's uncertain if this works reliably and we ran into multiple problems when trying this in the Nuxt SDK.

Once we've found a way to support Otel in SvelteKit, these are the concrete tasks we need to solve:

Tasks

Preview Give feedback

Importantly, we need to remain backwards-compatible with the current way of setting up the SDK as long as we don't release work in this issue with a new major version. We are free to deprecate anything that we deem to be removed in a future SDK version.

@Lms24 Lms24 added the Package: sveltekit Issues related to the Sentry SvelteKit SDK label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: sveltekit Issues related to the Sentry SvelteKit SDK
Projects
None yet
Development

No branches or pull requests

1 participant