Skip to main content
This page summarizes the main public APIs exported from @m4trix/tracing and @m4trix/trace-viewer.

Tracer

Use Tracer.from(...) to create a callback handler backed by a TraceStore.
Use tracer.adapt(toLangGraph) when you want an explicit LangGraph-oriented callback type (LangGraphTracer). You can also import toLangGraph from @m4trix/tracing/adapters/langgraph. Callback handlers on the adapted tracer:
  • handleChainStart, handleChainEnd, handleChainError
  • handleLLMStart, handleLLMEnd, handleLLMError
  • handleChatModelStart
  • handleToolStart, handleToolEnd, handleToolError
  • handleRetrieverStart, handleRetrieverEnd, handleRetrieverError
flush() waits for in-flight callback writes, writes pending runs in a batch, and upserts pending trace summaries.

TraceStore

Use TraceStore.of(...) to compose structure and payload adapters.
Methods:
  • upsertTrace(trace)
  • upsertRun(run)
  • upsertRunBatch(runs)
  • getTrace(traceId)
  • listTraces(query?)
  • putJsonPayload(path, value)
  • getPayload(ref)
  • putPayloadStream(path, body)
  • getPayloadStream(ref)
Stream methods require a payload adapter that implements putStream and getStream.

Filesystem Adapters

Use the built-in adapters for local traces:
FsStructureStoreAdapter writes:
  • traces/<traceId>/trace.json
  • traces/<traceId>/runs.ndjson
FsPayloadStoreAdapter writes JSON and stream payloads inside the configured root and rejects absolute paths or parent-directory refs.

TraceViewerApi

Use TraceViewerApi.from(...) to read traces for a UI or API layer.
Methods:
  • listTraces(query?)
  • getTrace(traceId)
  • getTraceTree(traceId)
  • getPayload(ref)
getTraceTree(...) returns { trace, root }, where root is a TraceRunNode with recursive children.

Data Types

Trace fields:
  • schemaVersion
  • traceId
  • rootRunId
  • projectId
  • name
  • status
  • startTime, endTime, latencyMs
  • tokens, costUsd
  • runCount
  • metadata
TraceRun fields:
  • schemaVersion
  • traceId
  • runId
  • parentRunId
  • type
  • name
  • status
  • startTime, endTime, latencyMs
  • tokens, costUsd, error
  • inputRef, outputRef, eventsRef
  • metadata, extra

Custom Adapters

Implement StructureStoreAdapter for trace and run records:
Implement PayloadStoreAdapter for JSON payloads and optional streams:

Trace Viewer Package

@m4trix/trace-viewer exports:
  • createFsTraceViewerApi(traceRootPath)
  • startTraceViewerServer({ traceViewerApi, port, host? })
  • appRouter
  • parseCliArgs(argv)
  • cliHelpText(program)
  • DEFAULT_PORT
  • DEFAULT_FS_RELATIVE_PATH