Environment variables (used to auto-detect OTLP config if configOverride not provided)
Service name for telemetry
OptionalconfigOverride: OTLPExporterConfig | nullOptional explicit OTLP config (skips env detection if provided)
// SvelteKit hooks.server.ts
import { initOTLP, type FlushContext } from '@grand-board/otel-cloudflare';
export async function handle({ event, resolve }) {
const ctx = initOTLP(event.platform?.env, 'my-service');
try {
return await resolve(event);
} finally {
// Use waitUntil if available, otherwise await
if (event.platform?.context?.waitUntil) {
event.platform.context.waitUntil(ctx.flush());
} else {
await ctx.flush();
}
}
}
Initialize OTLP collectors for a request
Call this at the beginning of your request handler. Returns a FlushContext that you should call flush() on at the end.