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:
IMPORTANT: Call initOTLP() before using this function to set up collectors. Call flush() after the request completes to export telemetry.
Optionaloptions: TraceHandlerOptions// SvelteKit hooks.server.ts
import { initOTLP, traceHandler } from '@grand-board/otel-cloudflare';
export async function handle({ event, resolve }) {
const ctx = initOTLP(event.platform?.env, 'my-service');
try {
return await traceHandler(event.request, async (span) => {
// Add custom attributes to span
span.setAttribute('user.id', event.locals.userId);
return resolve(event);
});
} finally {
if (event.platform?.context?.waitUntil) {
event.platform.context.waitUntil(ctx.flush());
} else {
await ctx.flush();
}
}
}
Alias for traceHandler - trace an incoming HTTP request