Tracer
Defined in: observability/tracer.ts:94
Accessors
durationMs
Get Signature
get durationMs(): number;Defined in: observability/tracer.ts:246
Total wall-clock span of the trace (ms), or 0 if empty.
Returns
number
startedAt
Get Signature
get startedAt(): number | undefined;Defined in: observability/tracer.ts:252
Epoch ms of the first recorded entry — the base for every entry's dt.
Returns
number | undefined
Constructors
Constructor
new Tracer(options?): Tracer;Defined in: observability/tracer.ts:110
Parameters
| Parameter | Type |
|---|---|
options | TracerOptions |
Returns
Tracer
Methods
clear()
clear(): void;Defined in: observability/tracer.ts:257
Drop all recorded entries and metadata, and reset the clock origin.
Returns
void
curls()
curls(options?): string[];Defined in: observability/tracer.ts:476
Every captured request rendered as a runnable curl, in turn order — paste
any to replay that exact call. Maps requests() through toCurl,
defaulting baseURL from meta.baseURL (seeded by onRequest) so the call
site doesn't stitch the endpoint together. Pass baseURL to override; the
rest of ToCurlOptions (apiKeyEnv, stream, pretty, path) pass
straight through.
Parameters
| Parameter | Type |
|---|---|
options | Omit<ToCurlOptions, "baseURL"> & { baseURL?: string; } |
Returns
string[]
Throws
if no baseURL is known — wire onRequest, or pass options.baseURL.
disclosure()
disclosure(): DisclosureStep[];Defined in: observability/tracer.ts:409
The progressive-disclosure timeline: one step per captured request, each
diffed against the previous to show tools added/removed and how the context
window grew. Requires observe() (the only seam that sees the request).
Returns
flush()
flush(): Promise<void>;Defined in: observability/tracer.ts:124
Flush the async write queue and await the sink. Call once at run end so the
tail isn't lost (no-op when only the synchronous log is used).
Returns
Promise<void>
format()
format(options?): string;Defined in: observability/tracer.ts:341
Full timeline, one entry per line: [+12ms] agent tool_end weather ok → "...".
Parameters
| Parameter | Type |
|---|---|
options | FormatOptions |
Returns
string
formatDisclosure()
formatDisclosure(options?): string;Defined in: observability/tracer.ts:436
Compact view of how disclosure evolved: tools ± and context size per turn.
Parameters
| Parameter | Type |
|---|---|
options | FormatOptions |
Returns
string
formatTrajectory()
formatTrajectory(options?): string;Defined in: observability/tracer.ts:373
Compact per-turn view: the action and its observations, with timings.
Parameters
| Parameter | Type |
|---|---|
options | FormatOptions |
Returns
string
observe()
observe(model): ModelClient;Defined in: observability/tracer.ts:190
Wrap a ModelClient so its StreamEvents are captured (finer grain) and the
system prompt + tool names are pulled from each request into meta.
Parameters
| Parameter | Type |
|---|---|
model | ModelClient |
Returns
onRawRequest()
readonly onRawRequest(body): void;Defined in: observability/tracer.ts:169
Tap for OpenAICompatibleModel({ onRawRequest }): captures the full
assembled request body off the wire — the exact JSON POSTed to the model,
with the complete tool-call history. One entry per model turn. Together with
meta.baseURL (from onRequest) these reconstruct a reproducible curl.
Parameters
| Parameter | Type |
|---|---|
body | unknown |
Returns
void
onRawSSE()
readonly onRawSSE(line): void;Defined in: observability/tracer.ts:159
Tap for OpenAICompatibleModel({ onRawSSE }): captures raw response-wire lines (fire-and-forget).
Parameters
| Parameter | Type |
|---|---|
line | string |
Returns
void
onRequest()
readonly onRequest(info): void;Defined in: observability/tracer.ts:177
Tap for OpenAICompatibleModel({ onRequest }): records the model id, base
URL, sampling params, and system prompt into meta.
Parameters
| Parameter | Type |
|---|---|
info | { baseURL?: string; model?: string; params?: Record<string, unknown>; system?: string; } |
info.baseURL? | string |
info.model? | string |
info.params? | Record<string, unknown> |
info.system? | string |
Returns
void
requests()
requests(): unknown[];Defined in: observability/tracer.ts:460
The request body POSTed each model turn, in turn order — the exact JSON the
provider sent, with the growing tool-call history. The structured accessor
for the request wire (the request_body entries from onRawRequest): it
owns the label filter and unwraps the RawRequest payload, so callers
don't reach into entries/data. Pair to curls() like trajectory() /
formatTrajectory(). Empty unless onRawRequest is wired.
Returns
unknown[]
setMeta()
setMeta(partial): void;Defined in: observability/tracer.ts:132
Merge run metadata, ignoring undefined fields so partial taps don't clear
what's already known.
Parameters
| Parameter | Type |
|---|---|
partial | Partial<TraceMeta> |
Returns
void
toJSON()
toJSON(): TraceDocument;Defined in: observability/tracer.ts:265
The whole trace as one JSON document: run config + compact timeline.
Returns
toJSONL()
toJSONL(): string;Defined in: observability/tracer.ts:485
One compact JSON object per line — machine-readable, append-friendly.
Returns
string
trajectory()
trajectory(): TrajectoryStep[];Defined in: observability/tracer.ts:279
Fold the agent events into one (action -> observations) pair per model turn.
assistant is the action; tools are the observations it produced. Built
only from "agent" entries, so it works whether or not SSE/model capture is on.
Returns
Properties
| Property | Modifier | Type | Default value | Description | Defined in |
|---|---|---|---|---|---|
entries | readonly | TraceEntry[] | [] | Every captured record, in arrival order. | observability/tracer.ts:96 |
meta | public | TraceMeta | undefined | Run-level config: model, params, system, tools, sessionId. | observability/tracer.ts:99 |
sink | readonly | EventSink | undefined | EventSink for runAgent({ onEvent }): captures the agent's events. Returns the writer's backpressure promise, which the loop awaits — so a full async write queue throttles the run rather than growing unbounded. | observability/tracer.ts:143 |