Mastra
Learn how to export Mastra AI tracing to Sentry.
This is a server-side exporter for Mastra AI tracing that uses the Node.js Sentry SDK. It requires Node.js or compatible runtimes. Requires @mastra/sentry@beta package.
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack. The Mastra Sentry Exporter sends tracing data to Sentry using OpenTelemetry semantic conventions, providing insights into model performance, token usage, and tool executions.
Install the Mastra Sentry exporter package:
npm install @mastra/sentry@beta
The Sentry exporter can automatically read configuration from environment variables:
import { SentryExporter } from "@mastra/sentry";
// Reads from SENTRY_DSN, SENTRY_ENVIRONMENT, SENTRY_RELEASE
const exporter = new SentryExporter();
You can also configure the exporter explicitly:
import { SentryExporter } from "@mastra/sentry";
const exporter = new SentryExporter({
dsn: process.env.SENTRY_DSN,
environment: "production",
tracesSampleRate: 1.0,
release: "1.0.0",
});
Exports a tracing event to Sentry. Handles SPAN_STARTED, SPAN_UPDATED, and SPAN_ENDED events.
await exporter.exportTracingEvent(event);
Force flushes any pending spans to Sentry without shutting down the exporter. Waits up to 2 seconds for pending data to be sent. Useful in serverless environments where you need to ensure spans are exported before the runtime terminates.
await exporter.flush();
Ends all active spans, clears internal state, and closes the Sentry connection. Waits up to 2 seconds for pending data to be sent.
await exporter.shutdown();
For complete documentation on using Mastra with Sentry, see the Mastra Sentry Exporter documentation.
@mastra/sentry:>=1.0.0-beta.2
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").