Skip to content

Commit a7b2430

Browse files
small docs addition
1 parent d9ab921 commit a7b2430

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

documentation/docs/30-advanced/68-observability.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ export default {
3737

3838
> [!NOTE] Tracing — and more significantly, observability instrumentation — can have a nontrivial overhead. Before you go all-in on tracing, consider whether or not you really need it, or if it might be more appropriate to turn it on in development and preview environments only.
3939
40+
## Agumenting SvelteKit's builtin tracing
41+
42+
SvelteKit provides access to the `root` span and the `current` span on the request event. The root span is the one associated with your root `handle` function, and the current span could be associated with `handle`, `load`, a form action, or a remote function, depending on the context. You can annotate these spans with any attributes you wish to record:
43+
44+
```js
45+
/// file: $lib/authenticate.ts
46+
async function authenticate() {
47+
const event = getRequestEvent();
48+
const user = await getAuthenticatedUser(event);
49+
event.tracing.root.setAttribute({ userId: user.id });
50+
}
51+
```
52+
4053
## Development quickstart
4154

4255
To view your first trace, you'll need to set up a local collector. We'll use [Jaeger](https://www.jaegertracing.io/docs/getting-started/) in this example, as they provide an easy-to-use quickstart command. Once your collector is running locally:

0 commit comments

Comments
 (0)