@tigorlazuardi/otel-cloudflare - v1.1.1
    Preparing search index...

    Variable traceRequestConst

    traceRequest: (
        ctx: ExecutionContext,
        request: Request,
        handler: (span: Span) => Promise<Response>,
        options?: TraceHandlerOptions,
    ) => Promise<Response> = traceHandler

    Alias for traceHandler - trace an incoming HTTP request

    Type Declaration

      • (
            ctx: ExecutionContext,
            request: Request,
            handler: (span: Span) => Promise<Response>,
            options?: TraceHandlerOptions,
        ): Promise<Response>
      • Trace an incoming HTTP request with full instrumentation

        This is a standalone function for use in non-standard environments like SvelteKit. It provides the same functionality as the instrumented fetch handler:

        • Creates SERVER span with HTTP semantic convention attributes
        • Extracts traceparent from request headers for distributed tracing
        • Captures request/response body (truncated to 8KB, text-based content only)
        • Logs request summary with method, path, status, size, and duration
        • Adds traceparent header to response for downstream correlation
        • Automatically initializes OTLP and flushes telemetry via ctx.waitUntil

        Parameters

        • ctx: ExecutionContext

          Cloudflare ExecutionContext (provides waitUntil for non-blocking flush)

        • request: Request

          The incoming HTTP request

        • handler: (span: Span) => Promise<Response>

          The request handler function that receives the span

        • Optionaloptions: TraceHandlerOptions

          Optional configuration

        Returns Promise<Response>

        // SvelteKit hooks.server.ts
        import { traceHandler } from '@tigorlazuardi/otel-cloudflare';

        export const handle: Handle = async ({ event, resolve }) => {
        return traceHandler(
        event.platform!.context,
        event.request,
        () => resolve(event),
        { env: event.platform?.env, serviceName: 'my-service' }
        );
        };
        // Next.js with OpenNext Cloudflare
        import { traceHandler } from '@tigorlazuardi/otel-cloudflare';
        import { getCloudflareContext } from '@opennextjs/cloudflare';

        export async function middleware(request: NextRequest) {
        const { env, ctx } = await getCloudflareContext();
        return traceHandler(ctx, request, () => NextResponse.next(), { env, serviceName: 'my-app' });
        }

    traceHandler for full documentation