Observability on Mastra platform
Mastra Platform Observability collects traces, logs, metrics, scores, and feedback from Mastra applications. Use it for hosted observability without deploying Studio or Server or configuring local observability storage.
QuickstartDirect link to Quickstart
Choose the setup path that matches your project.
New projectDirect link to New project
Create a managed Mastra project and enable Mastra Platform Observability when prompted:
- npm
- pnpm
- Yarn
- Bun
npm create mastra@latest
pnpm create mastra
yarn create mastra
bunx create-mastra
The create command authenticates with Mastra Platform and creates an observability project. It then mints an access token and writes MASTRA_PLATFORM_ACCESS_TOKEN and MASTRA_PROJECT_ID to .env.
Existing projectDirect link to Existing project
If you're adding Mastra to an existing application, run mastra init and enable Mastra Observability when prompted:
- npm
- pnpm
- Yarn
- Bun
npx mastra init
pnpm dlx mastra init
yarn dlx mastra init
bun x mastra init
The init command lets you select an existing platform project or create one. It then creates an access token and writes the credentials to .env.
Configure manuallyDirect link to Configure manually
Use manual configuration if you skipped platform setup or automatic provisioning failed.
- In Mastra Platform, create or open a project.
- Create an access token for the project's organization.
- Copy the project ID from the project page.
- Add both values to
.env:
MASTRA_PLATFORM_ACCESS_TOKEN=<your-platform-access-token>
MASTRA_PROJECT_ID=<your-project-id>
Register MastraPlatformExporter in your observability configuration:
import { Mastra } from '@mastra/core/mastra'
import { MastraPlatformExporter, Observability } from '@mastra/observability'
export const mastra = new Mastra({
observability: new Observability({
configs: {
default: {
serviceName: 'my-service',
exporters: [new MastraPlatformExporter()],
},
},
}),
})
The exporter reads the access token and project ID from the environment. Keep serviceName stable so you can distinguish applications and deployments when filtering observability data.
MastraPlatformExporter sends ended spans, logs, metrics, scores, and feedback. It buffers events and sends a batch when it reaches 1,000 events or has waited five seconds. Model chunk spans aren't exported.
MastraPlatformExporter replaced CloudExporter. CloudExporter remains available for backward compatibility but is deprecated. Use MastraPlatformExporter for new code.
Store data locallyDirect link to Store data locally
Add MastraStorageExporter if you also want to persist observability data to your configured Mastra storage and inspect it in local Studio:
import { Mastra } from '@mastra/core/mastra'
import { MastraPlatformExporter, MastraStorageExporter, Observability } from '@mastra/observability'
export const mastra = new Mastra({
observability: new Observability({
configs: {
default: {
serviceName: 'my-service',
exporters: [new MastraPlatformExporter(), new MastraStorageExporter()],
},
},
}),
})
See Mastra storage exporter for storage requirements and configuration.
View observability dataDirect link to View observability data
Open your project in Mastra Platform to inspect exported traces, logs, metrics, scores, and feedback. A Studio or Server deployment isn't required.
Use a consistent serviceName to filter data from a specific application or deployment.
Query observability dataDirect link to Query observability data
Query hosted observability data from the terminal with the Mastra CLI:
- npm
- pnpm
- Yarn
- Bun
npx mastra api trace list
pnpm dlx mastra api trace list
yarn dlx mastra api trace list
bun x mastra api trace list
The CLI can infer platform credentials from your project environment. See the mastra api CLI reference for available commands, filtering, pagination, credential resolution, and curl examples.