@grand-board/otel-cloudflare - v6.11.0
    Preparing search index...

    Function withTrace

    • Wraps a function with OpenTelemetry tracing. Automatically captures caller info and sets code.* attributes.

      If the callback returns a Promise, the span ends after the promise resolves/rejects. If the callback is synchronous, the span ends immediately after execution.

      Type Parameters

      • T

      Parameters

      Returns T

      // Basic usage
      withTrace((span) => {
      logger.info('doing something');
      return result;
      });
      // With parent from traceparent header
      const traceparent = request.headers.get('traceparent');
      withTrace((span) => {
      logger.info('handling request');
      }, { parent: traceparent, name: 'handleRequest' });