Implementation:Wandb Weave Patch Integration
| Knowledge Sources | |
|---|---|
| Domains | Instrumentation, Configuration |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
Concrete tool for explicitly enabling LLM provider tracing with optional configuration provided by the Wandb Weave library.
Description
The patch_openai(), patch_anthropic(), and similar patch_*() functions explicitly enable Weave tracing for a specific LLM provider. Each accepts an optional IntegrationSettings parameter to customize tracing behavior. Internally, they delegate to _patch_integration() which imports the provider module and applies the patcher.
Usage
Call patch_openai() (or the equivalent for your provider) after weave.init() when you need explicit control over integration patching or want to customize settings.
Code Reference
Source Location
- Repository: wandb/weave
- File: weave/integrations/patch.py
- Lines: L26-53 (_patch_integration), L56-300 (patch_openai, patch_anthropic, etc.)
Signature
def patch_openai(settings: IntegrationSettings | None = None) -> None:
"""Enable Weave tracing for OpenAI.
Must be called after weave.init() to enable OpenAI tracing.
"""
def patch_anthropic(settings: IntegrationSettings | None = None) -> None:
"""Enable Weave tracing for Anthropic."""
def patch_mistral(settings: IntegrationSettings | None = None) -> None:
"""Enable Weave tracing for Mistral."""
def patch_cohere(settings: IntegrationSettings | None = None) -> None:
"""Enable Weave tracing for Cohere."""
def patch_google_genai(settings: IntegrationSettings | None = None) -> None:
"""Enable Weave tracing for Google Generative AI."""
# ... 20+ more patch functions for other providers
Import
from weave.integrations.patch import patch_openai, patch_anthropic
# or access via weave module
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| settings | None | No | Per-integration configuration (op settings, enable/disable) |
Outputs
| Name | Type | Description |
|---|---|---|
| return | None | Side effect: provider SDK methods are wrapped with tracing |
Usage Examples
Explicit Patching
import weave
from weave.integrations.patch import patch_openai
weave.init("my-team/my-project")
patch_openai() # Explicitly enable OpenAI tracing