UNPKG

opentelemetry-instrumentation-fetch-node

Version:
55 lines (54 loc) 1.8 kB
/// <reference types="node" /> import { Instrumentation, InstrumentationConfig } from '@opentelemetry/instrumentation'; import { MeterProvider, Span, TracerProvider } from '@opentelemetry/api'; interface FetchRequest { method: string; origin: string; path: string; headers: string | string[]; } interface FetchResponse { headers: Buffer[]; statusCode: number; } export interface FetchInstrumentationConfig extends InstrumentationConfig { ignoreRequestHook?: (request: FetchRequest) => boolean; onRequest?: (args: { request: FetchRequest; span: Span; additionalHeaders: Record<string, string | string[]>; }) => void; } export declare class FetchInstrumentation implements Instrumentation { private channelSubs; private spanFromReq; private tracer; private config; private meter; readonly instrumentationName = "opentelemetry-instrumentation-node-18-fetch"; readonly instrumentationVersion = "1.0.0"; readonly instrumentationDescription = "Instrumentation for Node 18 fetch via diagnostics_channel"; private subscribeToChannel; constructor(config: FetchInstrumentationConfig); disable(): void; enable(): void; setTracerProvider(tracerProvider: TracerProvider): void; setMeterProvider(meterProvider: MeterProvider): void; setConfig(config: InstrumentationConfig): void; getConfig(): InstrumentationConfig; onRequest({ request }: { request: FetchRequest; }): void; onHeaders({ request, response }: { request: FetchRequest; response: FetchResponse; }): void; onDone({ request }: { request: FetchRequest; }): void; onError({ request, error }: { request: FetchRequest; error: Error; }): void; } export {};