Skip to main content
To use an agent for automatic setup, see the Quickstart.

Sign up

If you don’t have a Braintrust account, sign up for free at braintrust.dev.

Install the SDK

The Braintrust Ruby SDK requires Ruby 3.2 or later. Add the SDK to your project:
If you add the SDK to a Gemfile, run:

Set an API key

Create an API key in API key settings and set it as an environment variable:
.env
The SDK picks up your API key automatically, so remember to set it locally and in production. Keep it out of version control.

Set a project

Traces are logged to a project that you name. There are two ways to set it:
  • BRAINTRUST_DEFAULT_PROJECT, an environment variable you set alongside your API key.
  • default_project:, an argument to Braintrust.init.
Which one to use depends on how you instrument your app. Auto-instrumentation through braintrust/setup or braintrust exec calls Braintrust.init for you, so set the environment variable on those paths. If you call Braintrust.init yourself, pass default_project: and keep the project name with the rest of your application configuration.

Configure tracing

There are two ways to instrument your app:
  • Auto-instrumentation (recommended): The SDK automatically traces supported AI provider gems.
  • Manual instrumentation: Initialize Braintrust yourself and instrument specific provider clients. Use this approach if you need precise control over when instrumentation runs.
1

Initialize the SDK

Auto-instrumentation patches supported AI libraries before you make provider calls. Pick the setup style that fits your app:
Add the SDK to your Gemfile with require: "braintrust/setup":
Gemfile
Make sure your application loads Bundler before requiring application code:
app.rb
When braintrust/setup loads, it calls Braintrust.init and instruments the supported provider gems already loaded in the process. List provider gems before braintrust in your Gemfile so Bundler.require loads them first. Gems loaded after braintrust/setup runs are not instrumented.
Add the SDK to your Gemfile with require: "braintrust/setup":
Gemfile
Rails loads Bundler during boot, so the setup file runs as the app starts. If you prefer an initializer, require the setup file there instead:
config/initializers/braintrust.rb
To instrument a Ruby process without changing application source code, install the gem and wrap the command with braintrust exec:
Use --only or --except to filter integrations:
To filter integrations without changing the command, set BRAINTRUST_INSTRUMENT_ONLY or BRAINTRUST_INSTRUMENT_EXCEPT to a comma-separated list instead. These apply to the braintrust/setup path as well.
2

Find your AI provider

To learn more about what gets traced, find your AI provider in SDK integrations.

Verify tracing

Run your app and make an AI call. A trace will show up in your Braintrust Logs, usually within seconds.
If traces appear in Braintrust, you’ve successfully set up the SDK.
If your traces don’t appear in Braintrust, see Troubleshooting.

Next steps

Learn more about using the SDK to observe, evaluate, and improve your AI application:
  • Instrument — trace LLM calls and application logic
  • Observe — search and analyze production traces
  • Annotate — label traces and build datasets
  • Evaluate — measure quality and catch regressions
  • Deploy — ship to production with the AI gateway