Storage
Storage determines which observability signals persist, which queries are available, and whether metrics aggregation works. Use a dedicated observability store instead of your primary application store.
When to use storageDirect link to When to use storage
- Keep traces, logs, and metrics available in Mastra Studio during development.
- Enable metrics with an OLAP-capable observability store.
- Route the observability domain to a dedicated production backend.
QuickstartDirect link to Quickstart
The following example demonstrates the recommended local testing setup: route observability data to DuckDB while keeping the rest of your application on LibSQL.
import { Mastra } from '@mastra/core/mastra'
import { LibSQLStore } from '@mastra/libsql'
import { DuckDBStore } from '@mastra/duckdb'
import { MastraCompositeStore } from '@mastra/core/storage'
import { Observability, MastraStorageExporter } from '@mastra/observability'
export const mastra = new Mastra({
storage: new MastraCompositeStore({
id: 'composite-storage',
default: new LibSQLStore({
id: 'mastra-storage',
url: 'file:./mastra.db',
}),
domains: {
observability: await new DuckDBStore().getStore('observability'),
},
}),
observability: new Observability({
configs: {
default: {
serviceName: 'mastra',
exporters: [new MastraStorageExporter()],
},
},
}),
})
Signal supportDirect link to Signal support
Mastra storage-backed observability currently depends on an OLAP-capable backend for full signal support:
- DuckDB: Recommended for local testing and development.
- ClickHouse: Recommended for production observability.
- Mastra platform: Use
MastraPlatformExporterif you want hosted observability without managing the backend yourself.
Primary application stores such as LibSQL or PostgreSQL should not be used as the observability store. Route the observability domain separately with composite storage when you use MastraStorageExporter.
Local developmentDirect link to Local development
For local development, the recommended setup is:
LibSQLStorefor primary application storageDuckDBStorefor theobservabilitydomainMastraStorageExporterfor local Studio access
This setup is for local testing and development. It gives you persisted traces, logs, and metrics without introducing external infrastructure.
Production deploymentDirect link to Production deployment
Observability traffic is usually more write-heavy than the rest of the application. In production:
- Use
MastraStorageExporterwith ClickHouse for theobservabilitydomain when you keep observability in your own storage. - Use
MastraPlatformExporterif you want hosted Mastra platform observability instead of managing the backend yourself. - Do not route observability to your primary application store.
For backend compatibility details and exporter batching behavior, see Mastra Storage exporter.