Mastra is a TypeScript framework for building agents, workflows, and tool integrations on top of the Vercel AI SDK. Arize AX captures every Mastra agent run via the officialDocumentation Index
Fetch the complete documentation index at: https://arize-ax.mintlify.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
@mastra/arize exporter, which Mastra invokes from its observability layer when the dev server is running.
Prerequisites
- Node.js 18+
- An Arize AX account (sign up)
- An
OPENAI_API_KEYfrom the OpenAI Platform (or any other provider supported by@ai-sdk/*)
The
Mastra constructor registers the OTel SDK and the ArizeExporter as soon as it runs, so any entry point that imports your configured mastra value will emit spans — mastra dev is the easiest way to get there (it bundles your code and starts an HTTP playground at http://localhost:4111), but a plain tsx script that imports mastra and calls mastra.getAgent("...").generate(...) works just as well. The Running programmatically section below shows that pattern.Launch Arize AX
- Sign in to your Arize AX account.
- From Space Settings, copy your Space ID and API Key. You will set them as
ARIZE_SPACE_IDandARIZE_API_KEYbelow.
Install
Bootstrap a Mastra project (if you don’t already have one), then add the Arize AX exporter:Configure credentials
ArizeExporter reads ARIZE_SPACE_ID, ARIZE_API_KEY, and ARIZE_PROJECT_NAME from the environment. You can also pass them explicitly to the constructor (see below).
Setup tracing
Edit your project’s main Mastra entry point (typicallysrc/mastra/index.ts) to register the exporter:
ArizeExporter:
Run Mastra
Start the dev server — this is what wires OTel into your app:mastra dev does four things:
- Generates OTel bootstrap files into
.mastra/output/. - Registers the
ArizeExporteragainst the global tracer provider. - Starts the Mastra playground at
http://localhost:4111/playground. - Begins streaming spans to Arize AX as agents are invoked.
Expected output
Running programmatically
For automated tests, batch jobs, or production code that doesn’t need the playground UI, import themastra value and call getAgent(...).generate(...) directly. The Mastra constructor registers OTel + the ArizeExporter at module load, so spans flow exactly as they do under mastra dev:
tsx:
invoke_agent / model_step / model_chunk span tree appear in Arize AX. This is the mode our integration test harness drives — see the doc’s GitHub source for the full scaffold.
Verify in Arize AX
- Open your Arize AX space and select project
mastra-tracing-example. - Trigger an agent from the playground at
http://localhost:4111/playground, then return to Arize AX. You should see a new trace within ~30 seconds with this shape: aninvoke_agent <agentName>root span (AGENT) wrapsmodel_step <agentName>andmodel_chunk <agentName>LLM child spans, plus achat <model-id>LLM span with the prompt, response, and token usage attached. - If no traces appear, see Troubleshooting.
Troubleshooting
- No traces in Arize AX. Check that you actually import the
mastravalue before calling the agent — theMastraconstructor is what registers OTel. A script that imports an agent directly from./agents/<name>without ever touching the configuredmastrainstance will run the agent but skip registration. The pattern in the Running programmatically section importsmastrafirst. BatchSpanProcessor: span droppedwarnings, or partial traces. The process exited before the span batch was flushed. Addawait new Promise((r) => setTimeout(r, 8000))(ormastra.shutdown()if you’re on a version that exposes it) before the script exits, so the OTel exporter has time to drain.mastra devhandles this automatically because the dev server stays alive.401from OpenAI. VerifyOPENAI_API_KEYis set and your model selection is valid. The dev server inherits the shell environment that started it.- Auth errors from Arize AX. Re-check
ARIZE_SPACE_IDandARIZE_API_KEYwere set beforemastra devstarted. Restart the dev server after exporting them — already-running processes do not pick up new env vars. - Production / serverless deployments. Outside the dev server, you must register OTel yourself before Mastra runs. The
@mastra/arizeexporter still works, but you wire it in via your platform’s instrumentation entry point (e.g.instrumentation.tsin Next.js). See the Mastra observability docs for the platform-specific setup.