Skip to content

Commit 4284efc

Browse files
fixes
1 parent 5e13df9 commit 4284efc

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

apps/svelte.dev/content/blog/2025-18-14-sveltekit-integrated-observability.md

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,38 @@ authorURL: https://bsky.app/profile/gruntled.bsky.social
77

88
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](https://opentelemetry.io/) tracing, and a dedicated instrumentation setup file that ensures your monitoring tools work seamlessly.
99

10-
## First-party OpenTelemetry traces
11-
12-
SvelteKit can now emit [OpenTelemetry](https://opentelemetry.io) traces for the following:
13-
14-
- [`handle`](/docs/kit/hooks#Server-hooks-handle) hook (`handle` functions running in a [`sequence`](/docs/kit/@sveltejs-kit-hooks#sequence) will show up as children of each other and the root handle hook)
15-
- [`load`](/docs/kit/load) functions (includes universal `load` functions when they run on the server)
16-
- [Form actions](/docs/kit/form-actions)
17-
- [Remote functions](/docs/kit/remote-functions)
18-
19-
To enable trace emission, add the following to `svelte.config.js`:
10+
To opt in, upgrade SvelteKit and your adapter and add the following to your `svelte.config.js`:
2011

2112
```js
2213
/// file: svelte.config.js
2314
export default {
2415
kit: {
25-
+++experimental: {
16+
experimental: {
2617
tracing: {
2718
server: true
19+
},
20+
instrumentation: {
21+
server: true
2822
}
29-
}+++
23+
}
3024
}
3125
};
3226
```
3327

34-
If there are additional attributes you think might be useful, please file an issue on the [SvelteKit GitHub issue tracker](https://github.com/sveltejs/kit/issues).
28+
## First-party OpenTelemetry traces
3529

36-
## A convenient home for all of your instrumentation
30+
SvelteKit can now emit [OpenTelemetry](https://opentelemetry.io) traces for the following:
3731

38-
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.
32+
- [`handle`](/docs/kit/hooks#Server-hooks-handle) hook (`handle` functions running in a [`sequence`](/docs/kit/@sveltejs-kit-hooks#sequence) will show up as children of each other and the root handle hook)
33+
- [`load`](/docs/kit/load) functions (includes universal `load` functions when they run on the server)
34+
- [Form actions](/docs/kit/form-actions)
35+
- [Remote functions](/docs/kit/remote-functions)
3936

40-
To enable `instrumentation.server.ts`, add the following to your `svelte.config.js`:
37+
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](https://github.com/sveltejs/kit/issues).
4138

42-
```js
43-
/// file: svelte.config.js
44-
export default {
45-
kit: {
46-
+++experimental: {
47-
instrumentation: {
48-
server: true
49-
}
50-
}+++
51-
}
52-
};
53-
```
39+
## A convenient home for all of your instrumentation
40+
41+
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.
5442

5543
In Node, your instrumentation might look something like this:
5644

@@ -65,7 +53,7 @@ const { registerOptions } = createAddHookMessageChannel();
6553
register('import-in-the-middle/hook.mjs', import.meta.url, registerOptions);
6654

6755
const sdk = new NodeSDK({
68-
serviceName: 'test-sveltekit-tracing',
56+
serviceName: 'my-sveltekit-app',
6957
traceExporter: new OTLPTraceExporter(),
7058
instrumentations: [getNodeAutoInstrumentations()]
7159
});

0 commit comments

Comments
 (0)