Mastra

Automatically instrument Mastra agents for monitoring in Astro AI
View as Markdown

Instrument a Mastra agent so its model calls, tool calls, and agent steps appear in the Astro AI dashboard. The @astropods/adapter-mastra package — the same one that connects a Mastra agent to Astro AI messaging — auto-wires OpenTelemetry tracing when OTEL_EXPORTER_OTLP_ENDPOINT is set on the deployed container.

Before you start

  • A deployable Astro AI agent project built with Mastra.
  • Astro AI sets OTEL_EXPORTER_OTLP_ENDPOINT only on deployed containers, so traces appear once the agent runs on the platform — not during local development.

Set up

1

Install the adapter

$bun add @astropods/adapter-mastra
2

Serve the agent

1import { Agent } from "@mastra/core/agent";
2import { serve } from "@astropods/adapter-mastra";
3
4const agent = new Agent({
5 name: "My Agent",
6 model: "anthropic/claude-sonnet-4-6",
7 instructions: "You are a helpful assistant.",
8});
9
10serve(agent);

Calling serve() registers the agent with the messaging service and configures observability in the same step. The agent’s name is sent as the OpenTelemetry service.name, and the platform-injected OTEL_EXPORTER_OTLP_ENDPOINT is used for export.

If your project constructs its own Mastra instance (for example, for multi-agent workflows), serve() registers Astro AI’s observability alongside any existing observability instances on that Mastra.

Traces capture each turn’s model calls, tool calls, and agent steps, attributed to the deployed agent.

3

Verify

Deploy the agent, send it a message, then open the agent’s detail page in the Astro AI dashboard. Traces appear within ~30 seconds.

Troubleshooting

If nothing shows up:

  • Confirm OTEL_EXPORTER_OTLP_ENDPOINT is present in the deployed container.
  • Check the agent container logs for OpenTelemetry export errors.