Braintrust Exporter
Braintrust is an evaluation and monitoring platform that helps you measure and improve LLM application quality. The Braintrust exporter sends your traces to Braintrust, enabling systematic evaluation, scoring, and experimentation.
InstallationDirect link to Installation
npm install @mastra/braintrust@beta
ConfigurationDirect link to Configuration
PrerequisitesDirect link to Prerequisites
- Braintrust Account: Sign up at braintrust.dev
- Project: Create or select a project for your traces
- API Key: Generate in Braintrust Settings → API Keys
- Environment Variables: Set your credentials:
.env
BRAINTRUST_API_KEY=sk-xxxxxxxxxxxxxxxx
BRAINTRUST_PROJECT_NAME=my-project # Optional, defaults to 'mastra-tracing'
Basic SetupDirect link to Basic Setup
src/mastra/index.ts
import { Mastra } from "@mastra/core";
import { Observability } from "@mastra/observability";
import { BraintrustExporter } from "@mastra/braintrust";
export const mastra = new Mastra({
observability: new Observability({
configs: {
braintrust: {
serviceName: "my-service",
exporters: [
new BraintrustExporter({
apiKey: process.env.BRAINTRUST_API_KEY,
projectName: process.env.BRAINTRUST_PROJECT_NAME,
}),
],
},
},
}),
});
Complete ConfigurationDirect link to Complete Configuration
new BraintrustExporter({
// Required
apiKey: process.env.BRAINTRUST_API_KEY!,
// Optional settings
projectName: "my-project", // Default: 'mastra-tracing'
endpoint: "https://api.braintrust.dev", // Custom endpoint if needed
logLevel: "info", // Diagnostic logging: debug | info | warn | error
});
Using TagsDirect link to Using Tags
Tags help you categorize and filter traces in the Braintrust dashboard. Add tags when executing agents or workflows:
const result = await agent.generate({
messages: [{ role: "user", content: "Hello" }],
tracingOptions: {
tags: ["production", "experiment-v2", "user-request"],
},
});
Tags appear in Braintrust's trace view and can be used to filter and search traces. Common use cases include:
- Environment labels:
"production","staging" - Experiment tracking:
"experiment-v1","control-group" - Priority levels:
"priority-high","batch-job"