@mastra/arize exporter into a Mastra app to send traces to Arize AX.
Overview
You will configure the Arize AX exporter on a Mastra app, run an agent workflow, and read the resulting traces in Arize AX. The exporter setup applies to any Mastra app, whether you run it withmastra dev, inside a web framework such as Next.js, or as a script.
This guide assumes familiarity with:
- TypeScript, including
async/await - The Mastra building blocks:
Agent, tools created withcreateTool, and workflows built withcreateWorkflow - Environment variables and package installation with
npm
- Register the
@mastra/arizeexporter so Mastra emits traces to Arize AX - Capture agent runs and tool calls as traces with no changes to your agent logic
- Capture workflow runs and their steps as their own trace tree
- Verify and read the traces in Arize AX
- Wire the exporter into a production Next.js deployment
Before you start
You need:- An existing agent built with Mastra
- Node.js 22.13 or later (required by the current
@mastra/*packages) - An Arize AX account (sign up)
- An
ANTHROPIC_API_KEY, or a key for any other provider supported by Mastra.
Get your Arize AX credentials
Sign in to your Arize AX account and create a tracing project from Projects → New Tracing Project. The setup page shows the credentials you need: copy your Space ID, then click Create API Key to generate a key and save it somewhere safe. You set them asARIZE_SPACE_ID and ARIZE_API_KEY below, and they route your traces to the correct space.

@mastra/arize exporter once on your Mastra instance and from there, every agent, tool, and workflow on that instance is traced automatically, with no manual spans and no changes to your agent logic.
1
Install the exporter
Install the Arize AX exporter and Mastra’s observability package alongside The
@mastra/core. Add a model provider (@ai-sdk/anthropic here) and zod if your app does not already have them. The mastra dev CLI, added as a dev dependency, runs the local server you use to trigger agents below; a project created with npm create mastra@latest already has it.@mastra/arize package builds on OpenInference and OpenTelemetry semantic conventions, so the traces it emits carry standardized agent, LLM, tool, and workflow attributes that Arize AX reads directly.2
Configure credentials
Set your Arize AX and model-provider credentials as environment variables. The exporter reads them at startup, so you keep secrets out of your source.
ARIZE_PROJECT_NAME is the project your traces land in. Name it for the app so runs stay grouped where you expect them.3
Register the Arize AX exporter
Configure With no arguments,
observability on your Mastra instance, typically in src/mastra/index.ts. Passing an Observability instance with an ArizeExporter registers the OpenTelemetry SDK and the exporter when the Mastra constructor runs, so any entry point that imports this mastra value emits spans to Arize AX.src/mastra/index.ts
ArizeExporter reads ARIZE_SPACE_ID, ARIZE_API_KEY, and ARIZE_PROJECT_NAME from the environment. The presence of spaceId is what routes traces to Arize AX. To pass the values explicitly instead, hand them to the constructor:4
Trace an agent and its tools
You do not add anything to your agent or its tools to trace them. The The tool is passed to an agent, and the agent is registered on the instrumented When this agent runs, the exporter turns it into a trace: the run becomes an AGENT span, the
ArizeExporter you configured in the previous step captures any agent registered on the Mastra instance, so if you already have an agent, it is covered and you can skip ahead to running it. The example below shows how the pieces connect, so you can map it to your own app.get-nutrition returns calories and protein for a food from a static lookup table:src/mastra/tools/get-nutrition.ts
Mastra instance. That chain is the entire setup:src/mastra/agents/coach-agent.ts
get-nutrition call becomes a child TOOL span with its input and output, and the model calls appear as LLM spans in between.5
Trace a workflow
Workflows trace the same way. The example below is a two-step workflow built with When this workflow runs, it produces its own trace: an
createWorkflow and createStep. Registering it on the instrumented Mastra instance is all it takes:src/mastra/workflows/daily-plan.ts
invoke_workflow root span wrapping one span per step, each carrying the step’s input and output. A workflow in your own app traces the same way once it is registered.6
Run your agent and see traces
Start the Mastra dev server. It bundles your code, registers the exporter, and serves the Studio web UI locally.Open Studio, select your agent or workflow, and send it a message. Each run exports to Arize AX. Because the dev server stays alive, it flushes spans on its own, so there is nothing extra to wait for.
7
Verify in Arize AX
Open your Arize AX space and select the project you set in
ARIZE_PROJECT_NAME. Within about 30 seconds of a run, new traces appear:- The agent run shows an
invoke_agentroot span (AGENT) carrying the prompt, the final reply, the model name, and token counts. Each tool call appears as anexecute_toolchild span (TOOL) with its arguments and result, and the underlying model calls appear as LLM spans. - The workflow run shows an
invoke_workflowroot span wrapping one child span per step, each carrying the step’s input and output.
What gets captured
The@mastra/arize exporter records the shape of each run using OpenTelemetry and OpenInference semantic conventions:
- Agent spans. One
invoke_agentroot span per agent run, carrying the input messages, the final output, the model name, and token counts. - Tool spans. One
execute_toolchild span per tool invocation, with the tool name, arguments, and result, so you can see what the agent decided to do and what each tool returned. - LLM spans. The model generations behind each run, with prompt, response, model name, and token usage attached.
- Workflow spans. One
invoke_workflowroot span per workflow run, wrapping a child span for each step with the step’s input and output.
Trace tool usage
Because Mastra owns the agent loop, the exporter traces both the model’s decision to call a tool and your app actually running it. Every tool you register with an agent, or invoke from a workflow step, produces anexecute_tool span (TOOL) nested under the run, carrying the tool name, the arguments the model passed, and the value the tool returned. You get this with no manual instrumentation.
To trace work that sits outside Mastra, such as a database query or an HTTP call inside a tool’s execute function, add your own spans with the OpenTelemetry API. They nest under the active Mastra span automatically. See Combine auto and manual instrumentation for more information.
Run programmatically
For CI, tests, batch jobs, or any code without the dev server, import the configuredmastra value and call an agent or workflow directly. The import triggers exporter registration, so runs are traced exactly as they are under mastra dev.
run-agent.ts
npx tsx run-agent.ts. Workflows run the same way, through mastra.getWorkflow("dailyPlanWorkflow").createRun() and run.start({ inputData }). A long-running server flushes on its own; only short-lived processes need the wait above.
Run in production
In a deployed app, the same import-time registration applies: import your configuredmastra value wherever you invoke agents, and the exporter starts on the first import. One adjustment matters for Next.js.
For Next.js, the observability packages rely on native OpenTelemetry modules that must not be bundled by the server compiler. Add them to serverExternalPackages in next.config.ts, and import mastra from your route handlers as usual.
next.config.ts
mastra value in the code that serves requests. The import registers the exporter, so the agent call inside the handler is traced like any run in the walkthrough above. Keep the handler on the Node.js runtime, since the OpenTelemetry SDK needs Node APIs that the Edge runtime does not provide:
app/api/chat/route.ts
Troubleshooting
- No traces in Arize AX. Confirm
ARIZE_SPACE_IDandARIZE_API_KEYare set in the same shell that starts your app, and that you import the configuredmastravalue before invoking an agent. A script that imports an agent directly from./agents/<name>without ever touching themastrainstance runs the agent but never registers the exporter. - Partial traces, or a missing root span. A short-lived script exited before the batch flushed. Add
await new Promise((r) => setTimeout(r, 8000))after your final call so the exporter can drain.mastra devand long-running servers handle this automatically. - See what the exporter is doing. Pass
new ArizeExporter({ logLevel: "debug" })to log each queued span and confirmExport completed: N spans sent successfully. Remove it once you have confirmed traces flow. - Auth errors from Arize AX. Re-check
ARIZE_SPACE_IDandARIZE_API_KEY. Already-running processes do not pick up new environment variables, so restart after exporting them. 401or404from your model provider. Verify the provider key (for exampleANTHROPIC_API_KEY) is set and valid, and that your key has access to the model your agent requests.- Spans missing under Next.js. Confirm the observability packages are listed in
serverExternalPackagesand that the route runs on the Node.js runtime, not Edge.
Next steps
Mastra integration reference
The concise reference for the exporter, including Phoenix configuration.
Set up sessions
Group multi-turn runs into conversations with session and user IDs.
Customize your traces
Attach metadata, tags, and custom attributes to your spans.
Evaluate agents
Score tool selection, tool results, and goal completion.