UNPKG

autotel-cloudflare

Version:

The #1 OpenTelemetry package for Cloudflare Workers - complete bindings coverage, native CF OTel integration, advanced sampling

38 lines (35 loc) 898 B
/** * workers-honeycomb-logger style wrapper API * * @example * ```typescript * import { wrapModule } from 'autotel-cloudflare' * * const handler = { * async fetch(req, env, ctx) { * return new Response('Hello') * } * } * * export default wrapModule( * { service: { name: 'my-worker' } }, * handler * ) * ``` */ import { instrument } from './instrument'; import type { ConfigurationOption } from 'autotel-edge'; /** * Wrap a Cloudflare Workers module-style handler * Alternative API style inspired by workers-honeycomb-logger * * @param config Configuration (can be static object or function) * @param handler The worker handler to wrap * @returns Instrumented handler */ export function wrapModule<E, Q = any, C = any>( config: ConfigurationOption, handler: ExportedHandler<E, Q, C>, ): ExportedHandler<E, Q, C> { return instrument(handler, config); }