-
Notifications
You must be signed in to change notification settings - Fork 140
Description
Describe the bug
Weave’s documentation states that Google GenAI is automatically traced via implicit patching, but in practice from google import genai is not patched unless weave.integrations.patch_google_genai() is called explicitly, even when the import occurs after weave.init().
This differs from OpenAI, which is implicitly patched without an explicit patch call.
Reproduction
import weave # version 0.52.22
weave.init(project_name="google-genai")
from google import genai
client = genai.Client(api_key="...")
client.models.generate_content(
model="gemini-2.0-flash",
contents="What's the capital of France?",
)Observed behavior
- No Weave traces are captured unless
weave.integrations.patch_google_genai()is called explicitly.
Expected behavior (per docs)
- Google GenAI should be implicitly patched and traced without calling a patch function.
Documentation reference
Official docs show this exact pattern and state tracing is automatic:
https://docs.wandb.ai/weave/guides/integrations/google
Likely cause
From inspection of weave/integrations/patch.py, implicit patching appears to rely on:
- root-module matching (
root_module = fullname.split(".")[0]) - and/or
fullname == root_module
This works for openai but not for Google GenAI, which is imported as google.genai under the shared google namespace. As a result, the import hook does not trigger patching for google.genai, even when imported after weave.init().
Why this matters
- The documented usage pattern does not reliably work.
- Behavior differs from OpenAI despite similar “automatic tracing” claims.
- Users must discover and apply
patch_google_genai()manually, which contradicts the docs.
Suggested direction
- Ensure implicit patching recognizes
google.genaiexplicitly (without patching the entiregooglenamespace), or - Update documentation to reflect the need for explicit patching if this is intentional.
Weave Project Link
No response
Screenshots
No response