Libraries v5.2.0
    Preparing search index...

    Function tracingMiddleware

    • Creates a @cleverbrush/server middleware that opens an OpenTelemetry SERVER span for every incoming request.

      Register first with useRequest() so that the span wraps CORS, auth, request logging, and the handler — capturing the full request lifetime.

      Behavior:

      • Extracts inbound trace context from request headers (W3C traceparent, baggage).
      • Names the span ${operationId} if available, otherwise ${method} ${http.route}, otherwise ${method}.
      • Sets HTTP semantic-convention attributes (http.request.method, url.path, url.scheme, server.address, user_agent.original, http.route).
      • Records final HTTP status and ends once on response finish/close.
      • Marks server failures, timeouts and interruptions as ERROR. Exception details are omitted unless an explicit policy allows them.
      • Stashes the span at ctx.items.get(OTEL_SPAN_ITEM_KEY) for downstream code to enrich.

      Parameters

      Returns (ctx: any, next: () => Promise<void>) => Promise<void>

      a Middleware compatible with @cleverbrush/server

      import { tracingMiddleware } from '@cleverbrush/otel';

      createServer()
      .useRequest(tracingMiddleware({ excludePaths: ['/health'] }))
      .use(corsMiddleware)
      .use(authMiddleware)
      .listen(3000);