ConstTrace 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:
Cloudflare ExecutionContext (provides waitUntil for non-blocking flush)
The incoming HTTP request
The request handler function that receives the span
Optionaloptions: TraceHandlerOptionsOptional configuration
// 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' });
}
Alias for traceHandler - trace an incoming HTTP request