Setup
Install Braintrust and DSPy:.env
Instrument DSPy
- Python
Braintrust’s DSPy integration requires If you only want to patch DSPy instead of enabling all supported Python integrations, use Python resources:
dspy>=2.6.0.Automatic Instrumentation
braintrust.auto_instrument() patches dspy.configure() so Braintrust’s DSPy callback is added automatically when you configure DSPy.trace-dspy-auto.py
patch_dspy().trace-dspy-patch-only.py
Manual callback setup
UseBraintrustDSpyCallback() when you want to attach the callback explicitly. If you also want detailed LiteLLM token and cost spans, patch LiteLLM before importing DSPy.trace-dspy-manual.py
Examples
In Braintrust, a DSPy execution typically appears as a parent DSPy module span with child spans for adapter work and model calls. Example trace shape:- DSPy module spans such as
Predict,ChainOfThought, and other module executions - Adapter formatting and parsing spans
- LLM call inputs, outputs, and latency on
dspy.lmspans - Tool execution when your DSPy program invokes tools
- Extra LiteLLM token and cost spans when you patch LiteLLM