@zerolith/otel
v1.5.0
Published
OpenTelemetry spans for zerolith applications through @opentelemetry/api: a span per navigation, per hydration, and per request of the typed client with traceparent propagation
Maintainers
Readme
@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.
Install with npm install @zerolith/otel. The API is frozen at 1.0: a breaking change comes only in a major, after a deprecation notice, and the support policy says how long a line gets fixes.
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.
