Libraries
    Preparing search index...

    Function tracingMiddleware

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

      Should be registered as the first middleware 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} ${url.path}.
      • Sets HTTP semantic-convention attributes (http.request.method, url.path, url.scheme, server.address, user_agent.original, http.route).
      • Records http.response.status_code after next() completes.
      • Marks the span ERROR and records the exception on uncaught errors.
      • 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()
      .use(tracingMiddleware({ excludePaths: ['/health'] }))
      .use(corsMiddleware)
      .use(authMiddleware)
      .listen(3000);