Skip to content

Commit cae9bb7

Browse files
authored
Merge pull request #54 from mainframecomputer/sayak/mfe-440-add-better-onoff-switch-to-orchestra-braintrust-logging
Add configurable on/off switch for Braintrust integration
2 parents a290952 + 0ecf73e commit cae9bb7

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

docs/src/observability.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Observability
2+
3+
### Braintrust Integration
4+
5+
##### How do I enable or disable Braintrust integration?
6+
7+
Orchestra has built-in support for [Braintrust](https://www.braintrust.dev/), which provides observability and evaluation for LLM applications.
8+
9+
To enable Braintrust integration:
10+
1. Install the `braintrust` package: `pip install braintrust`
11+
2. Set your Braintrust API key as an environment variable:
12+
```
13+
export BRAINTRUST_API_KEY=your_api_key
14+
```
15+
3. By default, Braintrust is automatically enabled when the API key is present
16+
17+
To explicitly enable Braintrust integration:
18+
```
19+
export BRAINTRUST_ORCHESTRA_ENABLED=true
20+
```
21+
22+
To disable Braintrust integration inside Orchestra:
23+
```
24+
export BRAINTRUST_ORCHESTRA_ENABLED=false
25+
```
26+
27+
You can also use `0` or `no` as values to disable it, or `1` or `yes` to enable it. Braintrust integration is automatically enabled when:
28+
1. The `braintrust` package is installed
29+
2. The `BRAINTRUST_API_KEY` environment variable is set with a valid API key
30+
3. The `BRAINTRUST_ORCHESTRA_ENABLED` environment variable is either:
31+
- Set to enable it (`true`, `1`, or `yes`)
32+
- Not set at all (defaults to enabled when API key exists)
33+
34+
When enabled, Braintrust will trace all tool calls and requests to OpenAI, OpenRouter, Groq, Together AI, and Deepseek, providing detailed logs and analytics in your Braintrust dashboard.

packages/python/src/mainframe_orchestra/utils/braintrust_utils.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,32 @@
55
This module provides fallback decorators when Braintrust is not available.
66
"""
77

8-
try:
9-
from braintrust import traced, wrap_openai
10-
BRAINTRUST_AVAILABLE = True
11-
except ImportError:
12-
BRAINTRUST_AVAILABLE = False
13-
def traced(type=None):
14-
"""No-op decorator when Braintrust is not available"""
15-
def decorator(func):
16-
return func
8+
import os
9+
10+
# Check if Braintrust integration is explicitly enabled or disabled via environment variable.
11+
# Default to enabled if API key is present and no explicit setting
12+
BRAINTRUST_API_KEY_EXISTS = os.environ.get("BRAINTRUST_API_KEY", "") != ""
13+
BRAINTRUST_ENABLED = os.environ.get("BRAINTRUST_ORCHESTRA_ENABLED", "").lower() in ("true", "1", "yes") or (
14+
BRAINTRUST_API_KEY_EXISTS and os.environ.get("BRAINTRUST_ORCHESTRA_ENABLED", None) is None
15+
)
16+
17+
# Default implementation of no-op decorators
18+
def traced(func=None, **kwargs):
19+
"""No-op decorator when Braintrust is not available"""
20+
if func is None:
21+
def decorator(f):
22+
return f
1723
return decorator
18-
19-
def wrap_openai(func):
20-
"""No-op decorator when Braintrust is not available"""
21-
return func
24+
return func
25+
26+
def wrap_openai(func):
27+
"""No-op decorator when Braintrust is not available"""
28+
return func
29+
30+
# Try to import Braintrust if enabled
31+
if BRAINTRUST_ENABLED:
32+
try:
33+
from braintrust import traced, wrap_openai
34+
except ImportError:
35+
# Keep the no-op implementations defined above
36+
pass

0 commit comments

Comments
 (0)