Skip to content
prod e051e98
Browse

Observability

See production

Agents are non-deterministic, so production debugging is impossible without tracing. Mastra builds observability on OpenTelemetry: every model call, tool call, and workflow step emits a span, and those spans export to the tool of your choice. One request becomes one trace you can replay.

From call to dashboard

From call to dashboard 1. Calls (model · tool · step) → 2. Spans (OpenTelemetry) → 3. Exporter (OTEL / vendor) → 4. Backend (Langfuse · Braintrust) Calls model · tool · step Spans OpenTelemetry Exporter OTEL / vendor Backend Langfuse · Braintrust
Each model/tool/step call emits an OpenTelemetry span; an exporter ships the trace to your backend where you debug and monitor.

A single trace stitches together the whole request: the agent’s reasoning, each tool call with its validated input/output, and — for workflows — every step, branch, and suspend/resume. Because it all flows through the one runtime, you get a coherent timeline instead of scattered logs.

Point Mastra at an OTEL-compatible backend or a first-class integration (Langfuse, Braintrust). On a long-running host, tracing exports in the background; on serverless, flush before the function returns so spans aren’t lost:

// Serverless: flush pending traces before the invocation ends.
await mastra.getObservability().flush();

Traces can capture prompts and tool I/O — scrub anything sensitive before it leaves your system with a sensitive-data filter, and sample in high-traffic paths so you keep signal without exporting every span.


Reference: Observability overview · Tracing · Langfuse

Next: MCP — interoperate with the wider agent ecosystem.