Skip to main content

OpenTelemetry tracing over OTLP, with SvelteKit's own handle, load and action spans.

Server only: started from instrumentation.server.ts, which runs before the app. With tracing.server on, SvelteKit's own spans for handle, load, actions and remote functions are exported with yours, and the logger stamps every JSON line with the active trace.

14:01:58.102 INFO  [Telemetry] Tracing on { endpoint: 'http://collector:4318', serviceName: 'acme' }

trace 1ac71cda…
  sveltekit.handle.root            41ms
  └─ sveltekit.load                 29ms
     └─ projects.import             22ms

Usage

instrumentation.server.ts
import { Telemetry } from "@zedensix/ui/server/telemetry";

new Telemetry({
	serviceName: "acme",
	serviceVersion: process.env.APP_VERSION,
	endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
}).start();
vite.config.ts
import adapter from "@sveltejs/adapter-bun";
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";

export default defineConfig({
	plugins: [
		sveltekit({
			adapter: adapter({ buildOptions: { compile: true } }),
			tracing: { server: true },
		}),
	],
});