@zerolith/otel
Spans for zerolith applications through @opentelemetry/api, the one dependency this package has beyond zerolith. It adds nothing unless installed, and with the API's no-op tracer it costs nothing until an SDK is configured.
import { trace } from "@opentelemetry/api";
import { navigationObserver, tracedHydrate, tracedTransport } from "@zerolith/otel";
const tracer = trace.getTracer("my-app");
const router = createRouter(appRoutes, { observe: navigationObserver(tracer) });
const api = createClient<Api>(apiRoutes, { transport: tracedTransport(undefined, tracer) });
tracedHydrate(App(router), "#app", tracer);
navigationObserveropens a span when a navigation starts and ends it on commit, failure, or cancel, with the route name, the path, and the mode as attributes, andzerolith.navigation.canceledon a canceled one.tracedHydratewrapshydratein a span and records the number of mismatches.tracedTransportwraps a client transport in a client span per request, with the method, URL, and status, and injects atraceparentheader from the active span so the server's trace continues the browser's.
The guide is on the docs site.
Status: alpha. Install with npm install @zerolith/otel@alpha; the API may change before 1.0.
Documentation
- The observability guide explains it with examples that run as tests.
- The reference lists every export, generated from the source.
- New to zerolith? The tutorial builds an app step by step, and the playground runs code in the browser.
License
Apache-2.0. See LICENSE.