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 creates 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, and scores. A Studio or Server deployment isn't required. Query exported feedback through the hosted feedback API described below.
Use a consistent serviceName to filter data from a specific application or deployment.
To get notified when a value such as an error rate or cost crosses a threshold, create alerts.
Query observability dataDirect link to Query observability data
Browse hosted traces 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 reads MASTRA_PLATFORM_ACCESS_TOKEN and MASTRA_PROJECT_ID from your project environment and targets the US observability endpoint by default. See CLI target resolution for other authentication options and regional endpoints.
Use mastra api trace query to find completed traces by their fields or related spans. For example, find traces whose root span took more than five seconds:
npx mastra api trace query '{
"timeRange": {
"from": "2026-08-01T00:00:00.000Z",
"to": "2026-08-08T00:00:00.000Z"
},
"where": {
"op": "gt",
"left": { "path": "durationMs" },
"right": { "literal": 5000 }
},
"page": { "limit": 25 }
}'
Choose a time range containing your exported traces within your plan's data retention period, with from earlier than to. Results appear in data.traces.
Mastra Platform follows the same query and aggregate request structure as Mastra Server. Use the Query traces and spans reference for HTTP endpoints, filters, response shapes, pagination, and discovery:
| Task | CLI command | Reference |
|---|---|---|
| Find matching traces | mastra api trace query | Query traces |
| Find individual spans, including nested runs | mastra api span query | Query spans |
| Measure matching traces | mastra api trace aggregate | Aggregate traces |
| Measure individual spans | mastra api span aggregate | Aggregate spans |
Pass the request as one JSON argument to each command. Responses are nested under data.
Platform scope and differencesDirect link to Platform scope and differences
Use the X-Mastra-Project-Id HTTP header to select one project. The CLI sets it from MASTRA_PROJECT_ID, an explicit header, or your project configuration. Without a project scope, credentials authorized for organization-wide access can query across projects. Project-bound credentials remain restricted to their project. Project scoping is separate from predicates: don't put projectId in where.
Platform adds these fields and grouping options:
| Operation | Platform addition |
|---|---|
queryTraces() and querySpans() | Each result includes projectId. |
aggregateTraces() | Supports groupBy: ['projectId'] and countDistinct.projectId. |
aggregateSpans() | Supports groupBy: ['projectId'], but not countDistinct.projectId. |
All traces are retained for six months. This retention period is subject to change for all month-to-month plans. See pricing for current plan limits.
Search span contentDirect link to Search span content
Word search finds traces and spans by the words in span input, output, and error text. In the filter bar, pick a content field with the contains words operator: Any span content, Span input, Span output, or Span error on the Traces page, and Any Content, Input, Output, or Error on the Spans page. A search over more than 7 days can take up to a minute.
Through the API, use the hasAllTokens predicate. This query finds failed tool calls whose error contains both "connection" and "refused":
npx mastra api span query '{
"timeRange": {
"from": "2026-08-07T00:00:00.000Z",
"to": "2026-08-08T00:00:00.000Z"
},
"where": {
"op": "and",
"args": [
{ "op": "eq", "left": { "path": "spanType" }, "right": { "literal": "tool_call" } },
{ "op": "hasAllTokens", "left": { "path": "error" }, "right": { "literal": "connection refused" } }
]
},
"page": { "limit": 25 }
}'
In trace query and trace aggregate, put hasAllTokens inside spans.some. span query and span aggregate accept it directly in where.
Platform matches words this way:
- A span matches when the field contains every word, in any order. Phrase search isn't supported:
"connection refused"also matchesrefused connection. - Words match whole.
timedoesn't matchtimeout. - Any ASCII character other than a letter or digit separates words, including spaces, quotes,
-,_, and..user_idsearches foruserandid. Other characters, such as accented letters and CJK text, don't separate words. - Matching ignores the case of ASCII letters.
- With
all, one field must contain every word. Words found in different fields don't combine.
Word search has these limits:
| Limit | Value |
|---|---|
| Words per request | 5 distinct words, counted across all hasAllTokens predicates |
| Search text | 256 characters per predicate |
| Time range | 120 days |
| Request time, up to 7 days | Same as other queries |
| Request time, over 7 days | Up to 60 seconds |
| Searches over 7 days at once | 2 running and 4 waiting per organization |
A span is searched when it starts within the time range. A span that runs longer than 30 days can be missed.
mastra api stops waiting after 30 seconds by default. For a search over more than 7 days, pass a longer timeout in milliseconds, such as --timeout 90000.
Word search returns these errors:
| Status | Response | What to do |
|---|---|---|
404 | Text search is not available | Word search isn't enabled for your organization. Check the capabilities below. |
422 | TRACE_QUERY_INVALID with issue time_range_too_large | Search at most 120 days. |
422 | TRACE_QUERY_INVALID with issue invalid_literal | Search at most 5 words. |
422 or 504 | name: "search_too_expensive" | Narrow the time range or select one project. |
429 | name: "search_busy" with Retry-After: 60 | Other searches over 7 days are running in your organization. Retry after a minute or search a shorter range. |
Check traceQueryTokenSearch, traceAggregateTokenSearch, spanQueryTokenSearch, and spanAggregateTokenSearch from getObservabilityCapabilities() before searching. A false value means the operation doesn't accept word search for your organization. The Platform MCP server doesn't offer word search.
Other observability dataDirect link to Other observability data
You can query exported feedback over HTTP. See the Feedback API for its current status, regional endpoints, authentication, project scoping, and supported query parameters such as traceId and environment.
You can query exported metrics over HTTP, with MastraClient, or with mastra api metric. See the Metrics API for regional endpoints, authentication, project scoping, and supported endpoints.
Import existing tracesDirect link to Import existing traces
To move trace history from another provider, such as Langfuse, into a Mastra Platform project, see Import existing traces.