Introducing integrated observability in SvelteKit

Understanding how your SvelteKit application behaves in production — from request flows to performance bottlenecks — is crucial for building reliable user experiences. SvelteKit now has first-class support for observability: built-in OpenTelemetry tracing, and a dedicated instrumentation setup file that ensures your monitoring tools work seamlessly.

To opt in, upgrade SvelteKit and your adapter and add the following to your svelte.config.js:

svelte.config
export default {
 
kit: {
    experimental: {
        tracing: {
 server: boolean;
        };
        instrumentation: {
 server: boolean;
        };
    };
}
kit
: {
experimental: {
    tracing: {
        server: boolean;
    };
    instrumentation: {
        server: boolean;
    };
}
experimental
: {
tracing: {
    server: boolean;
}
tracing
: {
server: booleanserver: true },
instrumentation: {
    server: boolean;
}
instrumentation
: {
server: booleanserver: true } } } };

First-party OpenTelemetry traces

SvelteKit can now emit OpenTelemetry traces for the following:

The emitted spans include attributes describing the current request, such as http.route, and surrounding context, such as the +page or +layout file associated with a load function. If there are additional attributes you think might be useful, please file an issue on the SvelteKit GitHub issue tracker.

A convenient home for all of your instrumentation

Emitting traces alone is not enough: You also need to collect them and send them somewhere. Under normal circumstances, this can be a bit challenging. Because of the nature of observability instrumentation, it needs to be loaded prior to loading any of the code from your app. To aid in this, SvelteKit now supports a src/instrumentation.server.ts file which, assuming your adapter supports it, is guaranteed to be loaded prior to your application code.

In Node, your instrumentation might look something like this:

import { import NodeSDKNodeSDK } from '@opentelemetry/sdk-node';
import { import getNodeAutoInstrumentationsgetNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { import OTLPTraceExporterOTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { import createAddHookMessageChannelcreateAddHookMessageChannel } from 'import-in-the-middle';
import { function register<Data = any>(specifier: string | URL, parentURL?: string | URL, options?: Module.RegisterOptions<Data>): void (+1 overload)

Register a module that exports hooks that customize Node.js module resolution and loading behavior. See Customization hooks.

@sincev20.6.0, v18.19.0
@paramspecifier Customization hooks to be registered; this should be the same string that would be passed to import(), except that if it is relative, it is resolved relative to parentURL.
@paramparentURL f you want to resolve specifier relative to a base URL, such as import.meta.url, you can pass that URL here.
register
} from 'module';
const { const registerOptions: anyregisterOptions } = import createAddHookMessageChannelcreateAddHookMessageChannel(); register<any>(specifier: string | URL, parentURL?: string | URL, options?: Module.RegisterOptions<any>
Creată 1d | 18 aug. 2025, 21:50:04


Autentifică-te pentru a adăuga comentarii

Alte posturi din acest grup

What’s new in Svelte: August 2025

With Async Svelte and its companion Remote Functions officially ou

3 aug. 2025, 08:40:06 | Svelte
What’s new in Svelte: July 2025

Whether you’re trying out Vite 7, vitest browser mode or remote functions, there’s lots of experimental features to try t

30 iun. 2025, 20:20:06 | Svelte
What’s new in Svelte: June 2025

In addition to advancing the work on Async Svelte, the maintainers have been hard at work introducing long requested features like Attachments.

This month, we’ll share a bit about the

2 iun. 2025, 17:50:03 | Svelte
Bringing Svelte Summit to the whole community

This month’s Svelte Summit in Barcelona was a glorious celebration of the community. We had lively conversations, delightful dinners, and funny, im

21 mai 2025, 13:40:07 | Svelte
What’s new in Svelte: May 2025

Only a week until Svelte Summit Spring 2025! If you can’t make it in-person to Barcelona, you can purchase a virtual ticket

30 apr. 2025, 23:50:03 | Svelte
What’s new in Svelte: April 2025

With a couple minor releases of SvelteKit in the last month and a few more from Svelte itself, there’s a lot to be excited about this month. From new helper functions to new configuration opt

2 apr. 2025, 23:40:03 | Svelte
What’s new in Svelte: March 2025

SvelteHack 2024 has ended and the winners were announced on February 9th. Congrats to all the

4 mar. 2025, 16:50:04 | Svelte