Zen Router

OpenTelemetry

Automatic span attributes for matched routes.

Zen Router can automatically set span attributes on the active OpenTelemetry span when a route matches. This gives you per-route observability with a single config option.

Zen Router has no dependency on @opentelemetry/api itself. You provide the getActiveSpan function, so the coupling is entirely in your code.

Setup

Pass an otel config with a getActiveSpan function:

import { trace } from "@opentelemetry/api";

const zen = new ZenRouter({
  authorize,
  otel: {
    getActiveSpan: () => trace.getActiveSpan(),
  },
});

Span attributes

When a route matches, Zen Router sets these attributes on the active span:

AttributeExampleDescription
zen.routeGET /api/posts/<postId>The matched route pattern
zen.param.<name>zen.param.postId = "abc123"Each decoded path param

These attributes are set early in the request lifecycle, so they are recorded even if the request later fails due to auth or validation errors.

On this page

Made withHeartby Liveblocks