@braintrust/pi-extension package automatically traces pi sessions to Braintrust, including turns, model calls, and tool executions.
Prerequisites
Install pi
If you haven’t already, install pi:
Install the Braintrust extension
Install the package with pi:For a one-off run without installing it permanently, load the extension directly:
Usage
Once enabled, the extension traces each pi session as a hierarchy of spans:- Session spans: One root span per pi session that produces at least one turn
- Turn spans: One span per user prompt / agent run
- LLM spans: One span per model response inside a turn
- Tool spans: One span per tool execution
- A
Braintruststatus indicator in the footer while tracing is active - A trace widget below the editor with a shortened clickable Braintrust trace link when available
Configuration
You can configure the extension with environment variables or JSON config files. Configuration precedence is:- Defaults
~/.pi/agent/braintrust.json.pi/braintrust.json- Environment variables
Config file locations
- Global:
~/.pi/agent/braintrust.json - Project:
.pi/braintrust.json
Supported settings
| Config key | Env var | Default | Description |
|---|---|---|---|
trace_to_braintrust | TRACE_TO_BRAINTRUST | false | Enable or disable tracing |
api_key | BRAINTRUST_API_KEY | unset | Braintrust API key |
api_url | BRAINTRUST_API_URL | https://api.braintrust.dev | Braintrust API base URL. For EU organizations, use https://api-eu.braintrust.dev. For self-hosted deployments, use your data plane URL. |
app_url | BRAINTRUST_APP_URL | https://www.braintrust.dev | Braintrust app URL |
org_name | BRAINTRUST_ORG_NAME | unset | Organization name for project-scoped links |
project | BRAINTRUST_PROJECT | pi | Braintrust project that receives traces |
debug | BRAINTRUST_DEBUG | false | Enable debug logging |
additional_metadata | BRAINTRUST_ADDITIONAL_METADATA | {} | Extra metadata attached to session spans. When set via environment variable, pass a JSON object string. |
log_file | BRAINTRUST_LOG_FILE | unset | Write extension logs to a file. Set to true or auto to use the default log path. |
state_dir | BRAINTRUST_STATE_DIR | ~/.pi/agent/state/braintrust-pi-extension | Directory for extension session state and default logs |
parent_span_id | PI_PARENT_SPAN_ID | unset | Parent span ID for attaching pi traces under an existing trace |
root_span_id | PI_ROOT_SPAN_ID | unset | Root span ID to use when attaching to an existing trace |
Embed traces in parent traces
You can attach a pi session under an existing Braintrust trace. This is useful when pi is part of a larger workflow and you want the entire interaction to appear inside a parent trace. To attach a pi session under an existing span, setPI_PARENT_SPAN_ID:
PI_ROOT_SPAN_ID:
Troubleshooting
No traces are appearing
No traces are appearing
- Verify
TRACE_TO_BRAINTRUST=true. - Verify
BRAINTRUST_API_KEYis set in the shell where you launch pi. - Restart pi after changing environment variables or config files.
- Run at least one prompt. A session root span is only created for sessions that actually produce a turn.
pi shows 'Braintrust missing API key' or a config warning
pi shows 'Braintrust missing API key' or a config warning
- Check
echo $BRAINTRUST_API_KEY. - Validate the JSON syntax in
~/.pi/agent/braintrust.jsonor.pi/braintrust.json. - Make sure
BRAINTRUST_ADDITIONAL_METADATAcontains valid JSON if you set it as an environment variable.
I want debug logs
I want debug logs
Enable debug logging and restart pi:You can also force file logging explicitly:By default, logs are written under
~/.pi/agent/state/braintrust-pi-extension/.The trace link widget does not appear
The trace link widget does not appear
- The widget is only shown in interactive mode.
- Run at least one prompt so the extension has a trace to link to.
- If tracing is active but no link appears, enable debug logging and inspect the extension log file.
Next steps
- Explore the source: See the braintrust-pi-extension repository.
- Run evaluations: Check out the evaluation guide.
- Inspect traces: Open your Braintrust project in the Braintrust UI.