Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

6 changes: 0 additions & 6 deletions .isort.cfg

This file was deleted.

3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ repos:
# Ruff version.
rev: v0.12.7
hooks:
- id: ruff
- id: ruff-format
- id: ruff-check
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
Expand Down
2 changes: 0 additions & 2 deletions .prettierignore

This file was deleted.

14 changes: 3 additions & 11 deletions integrations/adk-py/examples/mcp_tracing/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ async def main():
SESSION_ID = "demo-session"

session_service = InMemorySessionService()
await session_service.create_session(
app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID
)
await session_service.create_session(app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID)

runner = Runner(agent=agent, app_name=APP_NAME, session_service=session_service)

Expand All @@ -74,15 +72,9 @@ async def main():
parts=[types.Part(text="What files are in /tmp? Just list a few.")],
)

async for event in runner.run_async(
user_id=USER_ID, session_id=SESSION_ID, new_message=user_msg
):
async for event in runner.run_async(user_id=USER_ID, session_id=SESSION_ID, new_message=user_msg):
if event.is_final_response():
text = (
event.content.parts[0].text
if event.content and event.content.parts
else "No response"
)
text = event.content.parts[0].text if event.content and event.content.parts else "No response"
print(f"Agent response: {text}\n")

print("=== Trace complete ===")
Expand Down
4 changes: 0 additions & 4 deletions integrations/adk-py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ dev = [
"ruff>=0.12.9",
]

[tool.isort]
profile = "black"
line_length = 120

[tool.ruff]
line-length = 120

Expand Down
14 changes: 0 additions & 14 deletions integrations/langchain-py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ members = [

[dependency-groups]
dev = [
"black",
"build",
"flake8",
"flake8-isort",
"httpx",
"isort==5.12.0",
"langchain-anthropic>=0.3.20",
"langchain-openai",
"langgraph>=0.2.1,<0.4.0",
Expand All @@ -62,16 +58,6 @@ dev = [
"twine",
]

[tool.black]
line-length = 120
target-version = ['py310']

[tool.isort]
profile = "black"
line_length = 120
known_first_party = ["braintrust_langchain"]
known_third_party = ["braintrust", "langchain"]

[tool.ruff]
line-length = 120

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
from re import Pattern
from typing import (
Any,
Dict,
List,
Optional,
Set,
TypedDict,
Union,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from contextvars import ContextVar
from typing import Optional

from langchain_core.tracers.context import register_configure_hook

Expand Down
1 change: 1 addition & 0 deletions integrations/langchain-py/src/tests/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def test_llm_calls(logger_memory_logger: LoggerMemoryLogger):
],
)


@pytest.mark.vcr
def test_chain_with_memory(logger_memory_logger: LoggerMemoryLogger):
logger, memory_logger = logger_memory_logger
Expand Down
1 change: 1 addition & 0 deletions internal/golden/adk-py-v1/google_adk.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from google.adk.sessions import InMemorySessionService
from google.genai import types


setup_adk(project_name="golden-py-adk")

FIXTURES_DIR = Path(__file__).parent.parent / "fixtures"
Expand Down
1 change: 1 addition & 0 deletions internal/golden/genai-py-v1/google_genai.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from google.genai import types
from google.genai.client import Client


setup_genai(project_name="golden-py-genai")

FIXTURES_DIR = Path(__file__).parent.parent / "fixtures"
Expand Down
1 change: 1 addition & 0 deletions internal/golden/langchain-py-v0/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI


init_logger(project="golden-py-langchain-v0")

handler = BraintrustCallbackHandler()
Expand Down
1 change: 1 addition & 0 deletions internal/golden/langchain-py-v1/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI


init_logger(project="golden-py-langchain-v1")

handler = BraintrustCallbackHandler()
Expand Down
1 change: 1 addition & 0 deletions internal/golden/pydantic-ai-v1/pydantic_ai_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from pydantic_ai.models.openai import OpenAIChatModel, OpenAIResponsesModel, OpenAIResponsesModelSettings


setup_pydantic_ai(project_name="golden-py-pydantic_ai")

FIXTURES_DIR = Path(__file__).parent.parent / "fixtures"
Expand Down
1 change: 1 addition & 0 deletions py/benchmarks/perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import braintrust
from braintrust import traced


LOOPS = 2000

braintrust.init_logger(project="perf_test")
Expand Down
1 change: 1 addition & 0 deletions py/examples/adk/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import braintrust


# Auto-instrument all supported libraries including Google ADK
braintrust.auto_instrument()

Expand Down
1 change: 1 addition & 0 deletions py/examples/adk/manual_patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from braintrust.wrappers.adk import setup_adk


# Setup ADK tracing with a specific project
setup_adk(project_name="my-adk-project")

Expand Down
1 change: 1 addition & 0 deletions py/examples/agno/async_simple_agent_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from braintrust.wrappers.agno import setup_agno


setup_agno(project_name="simple-agent-project")

from agno.agent import Agent
Expand Down
1 change: 1 addition & 0 deletions py/examples/agno/async_team_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from braintrust.wrappers.agno import setup_agno


# Set up Braintrust observability
setup_agno(project_name="async-team-agent-project")

Expand Down
2 changes: 2 additions & 0 deletions py/examples/agno/simple_agent.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from braintrust.wrappers.agno import setup_agno


setup_agno(project_name="simple-agent-project")

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.yfinance import YFinanceTools


# Create and configure the agent
agent = Agent(
name="Stock Price Agent",
Expand Down
2 changes: 2 additions & 0 deletions py/examples/agno/simple_agent_stream.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from braintrust.wrappers.agno import setup_agno


setup_agno(project_name="simple-agent-project")

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.yfinance import YFinanceTools


# Create and configure the agent
agent = Agent(
name="Stock Price Agent",
Expand Down
2 changes: 2 additions & 0 deletions py/examples/agno/team_agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from braintrust.wrappers.agno import setup_agno


# Set up Braintrust observability
setup_agno(project_name="team-agent-project")

Expand All @@ -8,6 +9,7 @@
from agno.team import Team
from agno.tools.yfinance import YFinanceTools


# Create specialized agents for the team
research_agent = Agent(
name="Research Analyst",
Expand Down
1 change: 1 addition & 0 deletions py/examples/anthropic_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import braintrust
from anthropic import AsyncAnthropic


# Initialize Anthropic client (needs ANTHROPIC_API_KEY)
client = braintrust.wrap_anthropic(AsyncAnthropic())

Expand Down
1 change: 1 addition & 0 deletions py/examples/anthropic_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import anthropic
import braintrust


# Initialize Anthropic client (needs ANTHROPIC_API_KEY)
client = braintrust.wrap_anthropic(anthropic.Anthropic())
braintrust.init_logger(project="example-anthropic-app")
Expand Down
2 changes: 2 additions & 0 deletions py/examples/auto_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import braintrust


# One-line instrumentation - call this BEFORE importing AI libraries
# This patches all supported libraries automatically
results = braintrust.auto_instrument()
Expand All @@ -36,6 +37,7 @@
import anthropic
import openai


# Create clients - they're automatically wrapped
openai_client = openai.OpenAI()
anthropic_client = anthropic.Anthropic()
Expand Down
1 change: 1 addition & 0 deletions py/examples/dspy/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# IMPORTANT: Patch LiteLLM BEFORE importing DSPy to get detailed token metrics
from braintrust.wrappers.litellm import patch_litellm


patch_litellm()

# Now import DSPy
Expand Down
14 changes: 8 additions & 6 deletions py/examples/evals/eval_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from braintrust import Eval


NUM_EXAMPLES = 10


Expand All @@ -12,9 +13,9 @@ async def exact_match_scorer(input, output, expected, trace=None):
score = 1.0 if output == expected else 0.0

if trace:
print("\n" + "="*80)
print("\n" + "=" * 80)
print(f"🔍 TRACE INFO for input: {input}")
print("="*80)
print("=" * 80)

# Print trace configuration
config = trace.get_configuration()
Expand All @@ -27,13 +28,13 @@ async def exact_match_scorer(input, output, expected, trace=None):
try:
spans = await trace.get_spans()
print(f"\n✨ Found {len(spans)} spans:")
print("-"*80)
print("-" * 80)

for i, span in enumerate(spans, 1):
print(f"\n Span {i}:")
print(f" ID: {span.span_id}")
span_type = span.span_attributes.get('type', 'N/A') if span.span_attributes else 'N/A'
span_name = span.span_attributes.get('name', 'N/A') if span.span_attributes else 'N/A'
span_type = span.span_attributes.get("type", "N/A") if span.span_attributes else "N/A"
span_name = span.span_attributes.get("name", "N/A") if span.span_attributes else "N/A"
print(f" Type: {span_type}")
print(f" Name: {span_name}")

Expand All @@ -50,10 +51,11 @@ async def exact_match_scorer(input, output, expected, trace=None):
if span.metadata:
print(f" Metadata: {list(span.metadata.keys())}")

print("\n" + "="*80 + "\n")
print("\n" + "=" * 80 + "\n")
except Exception as e:
print(f"\n⚠️ Error fetching spans: {e}")
import traceback

traceback.print_exc()
else:
print(f"⚠️ No trace available for input: {input}")
Expand Down
2 changes: 2 additions & 0 deletions py/examples/langsmith/eval_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@

import os


# Enable LangSmith tracing (required for traces to be sent to LangSmith)
os.environ.setdefault("LANGCHAIN_TRACING_V2", "true")
os.environ.setdefault("LANGCHAIN_PROJECT", "examples-wrappers-langsmith-eval")

# IMPORTANT: Call setup_langsmith BEFORE importing from langsmith
from braintrust.wrappers.langsmith_wrapper import setup_langsmith


# Set BRAINTRUST_STANDALONE=1 to completely replace LangSmith with Braintrust
standalone = os.environ.get("BRAINTRUST_STANDALONE", "").lower() in ("1", "true", "yes")

Expand Down
2 changes: 2 additions & 0 deletions py/examples/langsmith/tracing_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

import os


# Enable LangSmith tracing (required for traces to be sent to LangSmith)
os.environ.setdefault("LANGCHAIN_TRACING_V2", "true")
os.environ.setdefault("LANGCHAIN_PROJECT", "examples-wrappers-langsmith-tracing")

# IMPORTANT: Call setup_langsmith BEFORE importing from langsmith
from braintrust.wrappers.langsmith_wrapper import setup_langsmith


# Set BRAINTRUST_STANDALONE=1 to completely replace LangSmith with Braintrust
standalone = os.environ.get("BRAINTRUST_STANDALONE", "").lower() in ("1", "true", "yes")

Expand Down
1 change: 1 addition & 0 deletions py/examples/openai_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from braintrust import init_logger, traced, wrap_openai
from openai import OpenAI


logger = init_logger(project="example-openai-project")
client = wrap_openai(OpenAI())

Expand Down
2 changes: 2 additions & 0 deletions py/examples/otel/basic_otel_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import time


# Set environment variables
os.environ.setdefault("BRAINTRUST_PARENT", "project_name:otel-examples")

Expand All @@ -18,6 +19,7 @@
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
from opentelemetry.sdk.trace import TracerProvider


# Set up the tracer provider
provider = TracerProvider()
trace.set_tracer_provider(provider)
Expand Down
Loading
Loading