Thanks for contributing! Follow TDD practices: write tests first, implement minimal code, refactor.
# Clone repo
git clone git@github.com:braintrustdata/braintrust-sdk-ruby.git
cd braintrust-sdk-ruby
# Install system dependencies
./scripts/install-deps.sh
# Install mise (if needed)
curl https://mise.run | sh
# Add to shell: eval "$(mise activate bash)" # or zsh
# Install Ruby + tools (also runs bundle install)
mise install
# Install appraisals (for running examples)
bundle exec appraisal install
# Copy .env and add API keys
cp .env.example .env
# Verify setup
rakeUse the dev container if you prefer not to install Ruby tooling on your host machine. Your IDE edits files on the host; all tools run in the container.
# Clone repo
git clone git@github.com:braintrustdata/braintrust-sdk-ruby.git
cd braintrust-sdk-ruby
# Copy .env and add API keys
cp .env.example .env
# Enter interactive shell (first run builds the image)
docker compose run --rm -it devOnce in the dev container, finish setup (same as above):
# Install Ruby + tools (also runs bundle install)
mise install
# Install appraisals (for running examples)
bundle exec appraisal install
# Verify setup
rakeAll of our common dev tasks are in rake.
rake -T We use VCR for making http tests fast. You can run tests with these enabled, off, etc. If you add new tests you'll need to record new cassettes. See this for more details.
rake -T test:vcrTo add instrumentation support for a new library, use the integration generator:
rake contrib:generate NAME=trustybrain_llm AUTO_REGISTER=trueThis will create the integration structure and optionally register it. You can also specify additional options:
rake contrib:generate NAME=trustybrain_llm \
GEM_NAMES=trustybrain_llm,trustybrain \
REQUIRE_PATHS=trustybrain \
MIN_VERSION=1.0.0 \
MAX_VERSION=2.0.0 \
AUTO_REGISTER=trueIf you prefer to create the integration manually, follow these steps:
mkdir -p lib/braintrust/contrib/trustybrain_llm
mkdir -p test/braintrust/contrib/trustybrain_llmCreate lib/braintrust/contrib/trustybrain_llm/integration.rb:
# frozen_string_literal: true
require_relative "../integration"
module Braintrust
module Contrib
module TrustybrainLLM
class Integration
include Braintrust::Contrib::Integration
def self.integration_name
:trustybrain_llm
end
def self.gem_names
["trustybrain_llm"]
end
def self.loaded?
defined?(::TrustybrainLLM::Client) ? true : false
end
def self.patchers
require_relative "patcher"
[Patcher]
end
end
end
end
endCreate lib/braintrust/contrib/trustybrain_llm/patcher.rb:
# frozen_string_literal: true
require_relative "../patcher"
module Braintrust
module Contrib
module TrustybrainLLM
class Patcher < Braintrust::Contrib::Patcher
class << self
def applicable?
defined?(::TrustybrainLLM::Client)
end
def perform_patch(**options)
::TrustybrainLLM::Client.prepend(Instrumentation)
end
end
module Instrumentation
def chat(*args, **kwargs, &block)
Braintrust::Contrib.tracer_for(self).in_span("trustybrain_llm.chat") do
super
end
end
end
end
end
end
endAdd to lib/braintrust/contrib.rb:
require_relative "contrib/trustybrain_llm/integration"
# At the bottom:
Contrib::TrustybrainLLM::Integration.register!Create test files in test/braintrust/contrib/trustybrain_llm/:
# test/braintrust/contrib/trustybrain_llm/integration_test.rb
require "test_helper"
class Braintrust::Contrib::TrustybrainLLM::IntegrationTest < Minitest::Test
def test_integration_basics
integration = Braintrust::Contrib::TrustybrainLLM::Integration
assert_equal :trustybrain_llm, integration.integration_name
assert_equal ["trustybrain_llm"], integration.gem_names
end
# TODO: Add tests for patchers, availability, compatibility, and instrumentation
endSee existing tests in test/braintrust/contrib/ for complete examples of testing integrations, patchers, and the registry.
We use VCR for making http tests fast. You can run tests with these enabled, off, etc. If you add new tests you'll need to record new cassettes. See this for more details.
rake -T test:vcrCI tests against Ruby 3.2, 3.3, and 3.4. To test locally with a different Ruby version:
# Install a different Ruby version
mise install ruby@3.4
# Run tests with that version
mise exec ruby@3.4 -- bundle install
mise exec ruby@3.4 -- bundle exec rake test
# Run appraisal tests with that version
mise exec ruby@3.4 -- bundle exec appraisal install
mise exec ruby@3.4 -- bundle exec appraisal openai-0-33 rake testTo temporarily switch your shell to a different Ruby:
mise use ruby@3.4
ruby --version # => 3.4.x
bundle exec rake test