/** * OpenTelemetry adapter — emits HTTP client spans for every misina * request with the standard `http.*` / `url.*` / `network.*` semantic * conventions. * * Peer-dep duck-typed: pass anything that satisfies the minimal * `Tracer` shape (`@opentelemetry/api`'s real Tracer fits, an in-memory * fake fits, your own wrapper fits). Lets users opt into spans without * misina ever importing `@opentelemetry/*`. * * Complements `misina/tracing`: `tracing()` is the W3C trace context * *propagator* (sets `traceparent` / `baggage`); `otel()` is the * *span emitter* (creates and ends spans, attaches semconv attributes, * records exceptions). Use one, the other, or both. * * @example * ```ts * import { trace } from "@opentelemetry/api" * import { createMisina } from "misina" * import { otel } from "misina/otel" * * const api = createMisina({ * baseURL, * use: [otel({ tracer: trace.getTracer("my-service") })], * }) * ``` */ import type { MisinaPlugin } from "../types.mjs"; /** Minimal SpanContext shape used to format `traceparent`. */ export interface OtelSpanContext { traceId: string; spanId: string; traceFlags: number; } /** Minimal Span surface used by the adapter. */ export interface OtelSpan { setAttribute: (key: string, value: string | number | boolean) => void; setStatus: (status: { code: number; message?: string; }) => void; recordException: (error: unknown) => void; spanContext: () => OtelSpanContext; end: () => void; } /** Minimal Tracer surface — `tracer.startSpan(name, opts?)` is enough. */ export interface OtelTracer { startSpan: (name: string, options?: { attributes?: Record; kind?: number; }) => OtelSpan; } export interface OtelOptions { tracer: OtelTracer; /** * Override the span name. Default: `HTTP ` per the OTel * semantic conventions for HTTP client spans. */ spanName?: (request: Request) => string; /** * Inject `traceparent` based on the active span's context. Default: * true. Set false when the propagator (e.g. `withTracing`) is * already in the chain to avoid double-injection. */ injectTraceparent?: boolean; /** Extra attributes to add on every span. */ attributes?: Record; } /** * Plugin that emits OpenTelemetry HTTP client spans. One span per request * lifetime: started in `beforeRequest`, ended in `onComplete`. The span is * associated with the live `Request` via a WeakMap so we survive * `extend()` chains and per-request hook copies. */ export declare function otel(options: OtelOptions): MisinaPlugin;