Skip to content

Observability

Optional metrics, compile/run events, OTLP export, and Braintrust tracing. Everything is env-gated: nothing runs until you turn it on.

Install

# OpenTelemetry OTLP exporters
uv pip install "abt-core[observability]"
# Braintrust LangChain tracing
uv pip install "abt-core[braintrust]"

Both extras are independent — enable either or both.

Enable

Goal Env vars
In-process metrics + EventBus wiring ABT_OBSERVABILITY=1
OTLP span/metric export OTEL_EXPORTER_OTLP_ENDPOINT=https://… and [observability] extra
Braintrust experiment traces BRAINTRUST_API_KEY=… and [braintrust] extra

Optional: OTEL_SERVICE_NAME (default abt-core), BRAINTRUST_PROJECT (default abt-core).

OTLP vs in-process metrics

ABT_OBSERVABILITY=1 alone enables compile/run metrics and events without starting OTLP exporters. OTLP requires a non-empty OTEL_EXPORTER_OTLP_ENDPOINT and the observability extra.

OTLP authentication

Hosted collectors usually need an auth header. The exporters read the standard OpenTelemetry variable, so set it the same way as any OTel service:

export OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.example.com
export OTEL_EXPORTER_OTLP_HEADERS="authorization=Bearer%20<token>"

The value is comma-separated key=value pairs, percent-encoded (%20 is the space after Bearer). Load the token from your secret store; do not commit it.

What gets recorded

  • Compile — per-phase duration (discovery, wire, …) and total compile time
  • Run — agent stream start/finish, token counts, optional LLM/tool spans
  • MCP — cache hit/miss (when tool caching is enabled) and tool-list load latency

These are internal metric hooks, not lifecycle handlers. For agent success and failure handlers, see Lifecycle handlers.

Metric names

Counters and histograms are recorded when observability is on, and exported over OTLP when the endpoint is set.

Metric Type Meaning
abt.compile.finished counter Compiles completed
abt.compile.total_seconds histogram Total compile time
abt.compile.phase.<phase> counter One per compile phase (e.g. discovery, wire)
abt.compile.phase_seconds histogram Duration of each compile phase
abt.compile.cache.hit / abt.compile.cache.miss counter Partial-parse cache hits and misses
abt.run.agent.finished counter Agent runs finished
abt.run.agent.failed counter Agent runs that failed
abt.run.agent_seconds histogram Agent run wall time
abt.run.tokens.input / abt.run.tokens.output counter Tokens used by agent runs
abt.mcp.cache.hit / abt.mcp.cache.miss counter MCP tool-list cache hits and misses; .<source> suffix per MCP source
abt.mcp.load counter MCP tool-list loads
abt.mcp.load_seconds histogram MCP tool-list load latency

Quick smoke

ABT_OBSERVABILITY=1 records metrics in-process and prints nothing, so the smoke test that shows something needs an OTLP endpoint. Start any HTTP listener on port 4318 (a local OpenTelemetry Collector, or a few lines of Python that log each POST), then:

export ABT_OBSERVABILITY=1
export OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318
abt compile

It worked if the listener receives POST /v1/metrics and POST /v1/traces shortly after the command ends. With the endpoint unset nothing is sent.

Braintrust

Set BRAINTRUST_API_KEY and install [braintrust]. A fresh LangChain callback is attached per agent stream, so no workflow changes are needed.

Each MCP tool call also gets a tools/call <name> span nested under its tool span, so the round trip to the server shows up in the trace. The span carries timing and error status, not arguments, results or error text (the tool span already has those).

See also