/** * Surface 11 (V0.4) — `toW3CTraceContext(event, opts?)`. * * Pure mapper from a {@link DarwinTrajectoryEvent} to the * [W3C Trace Context](https://www.w3.org/TR/trace-context/) `traceparent` * header format so consumers can propagate Darwin trajectories into * external systems (Langfuse, Honeycomb, Datadog APM, Tempo) without * pulling in `@opentelemetry/api` as a dependency. * * Format reference (spec §3.2.2): * * traceparent = version "-" trace-id "-" parent-id "-" trace-flags * * - `version` = `"00"` (we emit only the current spec version). * - `trace-id` = 32 hex chars. We map LangChain's UUID `parentRunId` (if * present) by stripping dashes — UUID is 32 hex chars + 4 dashes — so * the strip yields exactly 32 chars. If `parentRunId` is undefined we * fall back to `runId` (top-level invokes form their own trace). * - `parent-id` = 16 hex chars. We map LangChain's UUID `runId` by * stripping dashes and TAKING THE FIRST 16 chars (parent-id is shorter * than trace-id by spec design — first 16 chars of a UUID are random * enough that collision probability per-trace is negligible). * - `trace-flags` = `"01"` (sampled). We always emit sampled — consumers * that want head-based sampling should drop the entire event upstream * rather than fiddle with the flag. * * The W3C spec forbids `trace-id == "00000000000000000000000000000000"` * and `parent-id == "0000000000000000"`. If either UUID strips to those * all-zero strings we return `undefined` rather than emit an invalid * header that downstream parsers reject. * * **Pure, no I/O, no allocation surprises.** The function builds a single * string. Safe to call inside `onTrajectory` hot paths. * * NEW V0.4 (S1235). */ import type { DarwinTrajectoryEvent } from "./with-darwin-evolution.js"; /** Options accepted by {@link toW3CTraceContext}. */ export interface ToW3CTraceContextOptions { /** * Override the trace-flags byte. Default `"01"` (sampled). Set `"00"` * for not-sampled — consumers can use this to mark trajectories that * would otherwise be sampled out before they reach the W3C-aware * exporter. */ traceFlags?: "00" | "01"; } /** Return shape: a single W3C-compliant `traceparent` header value. */ export interface W3CTraceContext { /** Full `traceparent` header value (spec §3.2). */ traceparent: string; /** 32-hex trace ID — convenience accessor. */ traceId: string; /** 16-hex span ID (the W3C `parent-id` slot) — convenience accessor. */ spanId: string; } /** * Convert a {@link DarwinTrajectoryEvent} into a W3C `traceparent` header * value. Returns `undefined` when no usable runId is present or when the * stripped UUIDs collapse to the all-zero strings the spec forbids. * * @example * ```ts * import { toW3CTraceContext, DarwinCallbackHandler } from "darwin-langgraph"; * * const handler = new DarwinCallbackHandler({ * nodeMap: { research: "researcher" }, * onTrajectory: async (event) => { * const ctx = toW3CTraceContext(event); * if (!ctx) return; * await fetch("https://langfuse.example/api/traces", { * method: "POST", * headers: { traceparent: ctx.traceparent }, * body: JSON.stringify({ trace: event.trajectory }), * }); * }, * }); * ``` */ export declare function toW3CTraceContext(event: DarwinTrajectoryEvent, opts?: ToW3CTraceContextOptions): W3CTraceContext | undefined; //# sourceMappingURL=to-w3c-trace-context.d.ts.map