/** * W3C Trace Context propagation for misina. Auto-injects `traceparent` * and forwards `tracestate` on every outgoing request. Pure JS using * `crypto.getRandomValues` (Web Crypto, available everywhere). * * - L1 spec: https://www.w3.org/TR/trace-context/ * - L2 spec: https://www.w3.org/TR/trace-context-2/ * * Compose with OpenTelemetry by passing `getCurrentSpan` so misina pulls * the active span context instead of generating a fresh root. * * @example * ```ts * import { createMisina } from 'misina' * import { tracing } from 'misina/tracing' * * const api = createMisina({ baseURL, use: [tracing()] }) * await api.get('/users/42') // request gets a fresh traceparent + matching tracestate * * // With OpenTelemetry: * import { trace } from '@opentelemetry/api' * const api2 = createMisina({ * baseURL, * use: [ * tracing({ * getCurrentSpan: () => { * const span = trace.getActiveSpan() * return span ? { traceId: span.spanContext().traceId, parentId: span.spanContext().spanId } : null * }, * }), * ], * }) * ``` */ import type { MisinaPlugin } from "../types.mjs"; export interface TracingOptions { /** * Pull the parent span context from an external tracing system. Return * `null` to fall back to a freshly-generated root span. The returned * `traceId` must be 32 hex chars; `parentId` 16. `flags` is an integer * 0-255; `state` is the W3C tracestate header value. */ getCurrentSpan?: () => TraceSpanContext | null; /** * Static or dynamic baggage entries appended to the W3C `Baggage` * header. https://www.w3.org/TR/baggage/ */ baggage?: Record | (() => Record); /** Override traceparent flags (default: 01 — sampled). */ flags?: number; } export interface TraceSpanContext { traceId: string; parentId: string; flags?: number; state?: string; } export declare function tracing(options?: TracingOptions): MisinaPlugin;