Skip to main content

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.

Installation
Direct link to Installation

npm install @mastra/braintrust@beta

Configuration
Direct link to Configuration

Prerequisites
Direct link to Prerequisites

  1. Braintrust Account: Sign up at braintrust.dev
  2. Project: Create or select a project for your traces
  3. API Key: Generate in Braintrust Settings → API Keys
  4. Environment Variables: Set your credentials:
.env
BRAINTRUST_API_KEY=sk-xxxxxxxxxxxxxxxx

# Optional
BRAINTRUST_ENDPOINT=https://api.braintrust.dev # Custom endpoint if needed

Zero-Config Setup
Direct link to Zero-Config Setup

With environment variables set, use the exporter with no configuration:

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()],
},
},
}),
});

Explicit Configuration
Direct link to Explicit Configuration

You can also pass credentials directly (takes precedence over environment variables):

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: "my-project",
}),
],
},
},
}),
});

Complete Configuration
Direct 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 Tags
Direct 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"