Your Phoenix API key can be found on the Keys section of your dashboard.
Launch your local Phoenix instance:
pipinstallarize-phoenixphoenixserve
This will expose the Phoenix on localhost:6006
For details on customizing a local terminal deployment, see Terminal Setup.
Set your Phoenix endpoint and API Key:
export PHOENIX_COLLECTOR_ENDPOINT="http://localhost:6006/v1/traces"export PHOENIX_API_KEY="YOUR PHOENIX API KEY"# only necessary if you've enabled auth
export PHOENIX_COLLECTOR_ENDPOINT="http://localhost:6006/v1/traces"export PHOENIX_API_KEY="YOUR PHOENIX API KEY"# only necessary if you've enabled auth
For more info on using Phoenix with Docker, see Docker.
Setup
Install packages:
npminstall@arizeai/openinference-mastra
Initialize OpenTelemetry tracing for your Mastra application:
import { Mastra } from"@mastra/core";import { OpenInferenceOTLPTraceExporter, isOpenInferenceSpan,} from"@arizeai/openinference-mastra";exportconstmastra=newMastra({// ... other config telemetry: { serviceName:"openinference-mastra-agent",// you can rename this to whatever you want to appear in the Phoenix UI enabled:true, export: { type:"custom", exporter:newOpenInferenceOTLPTraceExporter({ url:process.env.PHOENIX_COLLECTOR_ENDPOINT, headers: { Authorization:`Bearer ${process.env.PHOENIX_API_KEY}`,// if you're self-hosting Phoenix without auth, you can remove this header },// optional: filter out http, and other node service specific spans// they will still be exported to Mastra, but not to the target of// this exporter spanFilter: isOpenInferenceSpan, }), }, },});
From here you can use Mastra as normal. All agents, workflows, and tool calls will be automatically traced.
Example Agent Walkthrough
Here is a full project example to get you started:
Launch Phoenix using one of the methods above
The rest of this tutorial will assume you are running Phoenix locally on the default localhost:6006 port.
Create a new Mastra project
npm create mastra@latest
# answer the prompts, include agent, tools, and the example when asked
cd chosen-project-name
npm install --save @arizeai/openinference-mastra
Connect to Phoenix
Add the OpenInference telemetry code to your index.js file. The complete file should now look like this: