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:Set an API key
Create an API key in API key settings and set it as an environment variable:.env
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 toBraintrust.init.
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.
- Auto-instrumentation
- Manual instrumentation
1
Initialize the SDK
Auto-instrumentation patches supported AI libraries before you make provider calls. Pick the setup style that fits your app:
Bundler applications
Bundler applications
Add the SDK to your Gemfile with Make sure your application loads Bundler before requiring application code:When
require: "braintrust/setup":Gemfile
app.rb
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.Rails
Rails
Add the SDK to your Gemfile with 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:
require: "braintrust/setup":Gemfile
config/initializers/braintrust.rb
CLI wrapper
CLI wrapper
To instrument a Ruby process without changing application source code, install the gem and wrap the command with Use To filter integrations without changing the command, set
braintrust exec:--only or --except to filter integrations: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.
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