import { type Span } from '@opentelemetry/api'; /** * A function with the same shape as `fetch`. * * Kept local instead of importing from `@cleverbrush/client` so this * entrypoint remains structurally compatible without a runtime dependency. */ export type FetchLike = (url: string, init: RequestInit) => Promise; /** * Middleware shape accepted by `@cleverbrush/client`. */ export type ClientMiddleware = (next: FetchLike) => FetchLike; /** * Endpoint metadata attached to `RequestInit` by `@cleverbrush/client`. * * This is intentionally structural and partial so the OTel package can read * metadata when present without coupling to client internals at runtime. */ export interface ClientTracingEndpointMeta { group?: string; endpoint?: string; method?: string; path?: string; collectionPath?: string; operationId?: string | null; tags?: readonly string[]; } /** * Information passed to the `enrichSpan` hook. */ export interface ClientTracingInfo { url: string; method: string; headers: Record; endpoint?: ClientTracingEndpointMeta; } /** * Configuration for {@link clientTracingMiddleware}. */ export interface ClientTracingMiddlewareOptions { /** * Tracer name used when resolving the OTel tracer. * * @default '@cleverbrush/otel' */ tracerName?: string; /** Tracer version. */ tracerVersion?: string; /** * Predicate for skipping tracing on selected outbound requests. */ skip?: (url: string, init: RequestInit) => boolean; /** * Hook for adding custom attributes/events before the request is sent. * Errors thrown here are swallowed. */ enrichSpan?: (span: Span, info: ClientTracingInfo) => void; /** * Whether to record `url.full`. * * Disabled by default because full URLs can include query strings with * sensitive values. * * @default false */ recordUrlFull?: boolean; } /** * Creates a `@cleverbrush/client` middleware that traces outbound HTTP calls * and injects W3C Trace Context headers. * * Register this as the first client middleware so it wraps retries, timeouts, * and batching. The server-side `tracingMiddleware` already extracts these * headers, so downstream services join the same distributed trace. * * @example * ```ts * import { createClient } from '@cleverbrush/client'; * import { clientTracingMiddleware } from '@cleverbrush/otel/client'; * * const client = createClient(api, { * baseUrl: 'http://service-b:3000', * middlewares: [clientTracingMiddleware()] * }); * ``` */ export declare function clientTracingMiddleware(options?: ClientTracingMiddlewareOptions): ClientMiddleware;