/** * W3C Trace Context ( traceparent ) utilities. * * Pure, dependency-free and cross-platform ( Node 20+ and browsers ) — randomness * is sourced from the WHATWG `crypto.getRandomValues`, available on `globalThis` * in both environments, so this module deliberately does NOT import * `node:crypto` and stays safe to bundle for the browser. * * A W3C `traceparent` header has the shape: * * version "-" trace-id "-" parent-id "-" trace-flags * 00 - 32 hex - 16 hex - 2 hex * * See https://www.w3.org/TR/trace-context/#traceparent-header. */ /** * Minimal trace context this service carries on the ambient store and emits on * the outbound `traceparent` header. */ export interface ITraceContext { /** 32-hex-char trace id, shared by every span across services in one trace. */ traceId: string; /** 16-hex-char span id identifying this service's span within the trace. */ spanId: string; /** Whether the trace is sampled ( low bit of the trace-flags ). */ sampled: boolean; } /** * Parse & validate an inbound `traceparent` header value. * * @returns the decomposed parts ( plus the derived `sampled` flag ), or `null` * when the value is missing / malformed / forbidden by the spec * ( all-zero trace-id, all-zero parent-id, or version `ff` ). */ export declare function parseTraceparent(value: string | undefined | null): { version: string; traceId: string; parentId: string; flags: string; sampled: boolean; } | null; /** * A fresh random trace id ( 16 bytes -> 32 lowercase hex chars ). */ export declare function randomTraceId(): string; /** * A fresh random span id ( 8 bytes -> 16 lowercase hex chars ). */ export declare function randomSpanId(): string; /** * Render a {@link ITraceContext} as a W3C `traceparent` header value. */ export declare function formatTraceparent(ctx: ITraceContext): string; /** * Derive this service's trace context for a request. * * When `inboundTraceparent` is a valid header we CONTINUE the trace: the trace * id and sampled decision are inherited, and a fresh span id is minted for this * service's own span ( its parent being the inbound `parent-id` ). Otherwise a * brand-new, sampled trace is STARTED. */ export declare function newTraceContext(inboundTraceparent?: string | null): ITraceContext; //# sourceMappingURL=traceparent.d.ts.map