Setup
Install the Braintrust and RubyLLM gems, then configure your API keys.1
Install gems
2
Set environment variables
.env
Auto-instrumentation
To trace RubyLLM without modifying how you construct chats, loadbraintrust/setup before you require ruby_llm. Braintrust intercepts the require and patches RubyLLM::Chat, so every chat, tool, and streaming call emits a span. Loading braintrust/setup also initializes Braintrust for you and logs to the project set by BRAINTRUST_DEFAULT_PROJECT.Manual instrumentation
To trace RubyLLM calls manually, enable instrumentation yourself withBraintrust.instrument!(:ruby_llm). Once enabled, every chat, tool, and streaming call emits a span. The following app.rb initializes Braintrust, instruments RubyLLM, and makes a request:target: Braintrust.instrument!(:ruby_llm, target: chat).What Braintrust traces
Braintrust captures:- Chat completion spans (
ruby_llm.chat), with input messages, the model, and provider metadata, plus the assistant response and finish reason. - Tool execution spans (
ruby_llm.tool.<name>), with the tool name, call ID, arguments, and returned result. Tool schemas passed to the model are captured on the chat span. - Token usage metrics (prompt, completion, total, and cached tokens) for chat completions.
- Streaming responses, aggregated onto the chat span with time to first token.
- Multimodal message content, including text with image and file attachments.
- Errors, recorded on the span when a request raises.