Automatically initialize and instrument with braintrust exec
#83
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
This PR introduces a new
braintrust execCLI command that enables auto-instrumentation of Ruby applications without any code changes. This is the third and most frictionless approach to enabling Braintrust tracing, complementing the existingBraintrust.initandrequire "braintrust/setup"methods.The key benefit is that users can instrument existing applications simply by prefixing their run command with
braintrust exec --.Usage Examples
Before you begin: the
braintrustgem must be installed on your system to make the CLI available in your PATH.Basic Usage
Filtering Integrations
Help and Version
Comparison: Three Approaches to Auto-Instrumentation
Braintrust.initrequire "braintrust/setup"braintrust exec -- cmdNOTE: Using
braintrust execrequires thebraintrustgem be installed onto your system (if you want zero-code changes to an application). This means there are inherent limitations for compatibility, as the system-installed version of thebraintrustgem could potentially have conflicts with your Ruby application dependencies.Using this CLI approach is for when you can't easily add the
braintrustgem directly to your application. We recommend usingrequire 'braintrust/setup'in combination with Bundler in your Ruby application whenever possible to maximize compatibility.Environment Variables
BRAINTRUST_API_KEYBRAINTRUST_INSTRUMENT_ONLY--only)BRAINTRUST_INSTRUMENT_EXCEPT--except)Architectural Overview
How It Works
The CLI uses Ruby's
RUBYOPTenvironment variable to inject-rbraintrust/setupbefore the target application runs:CLI Implementation Details
The CLI module in
exe/braintrust:--onlyand--exceptflags for filtering integrations--separator to distinguish CLI args from command argsBRAINTRUST_INSTRUMENT_ONLY/BRAINTRUST_INSTRUMENT_EXCEPTenv vars for filteringENOENT(command not found),EACCES, andENOEXECFiles Added
exe/braintrustexamples/setup/exec.rbexamples/setup/exec_minimal.rbexamples/setup/README.md