Skip to content

Commit 0611712

Browse files
authored
fix(llmobs): [MLOB-3857] avoid importing from genai on startup (#14542)
This PR resolves an issue where Google Genai LLM spans were missing from Pydantic AI traces because we were importing from `google.genai.types` from within the Google GenAI integration upon startup. This was causing Google GenAI to not be patched when it was imported from within the Pydantic AI library. I have moved the import causing this issue into the method where it is used to avoid this issue. | Before | After | | --- | --- | | <img width="2746" height="590" alt="image" src="https://github.com/user-attachments/assets/1ada34f4-7b48-4997-80c0-f63d7067105e" /> | <img width="2746" height="614" alt="image" src="https://github.com/user-attachments/assets/a68dc13c-c0fb-4eda-885a-13042910b093" /> (note it is expected that the execution flow viz is not available because there are no span links implemented yet for GenAI tool calls) | ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
1 parent ea8e783 commit 0611712

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

ddtrace/llmobs/_integrations/google_genai.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
from typing import List
44
from typing import Optional
55

6-
7-
try:
8-
from google.genai.types import FunctionDeclaration
9-
except ImportError:
10-
FunctionDeclaration = None
11-
126
from ddtrace._trace.span import Span
137
from ddtrace.llmobs._constants import INPUT_DOCUMENTS
148
from ddtrace.llmobs._constants import INPUT_MESSAGES
@@ -187,6 +181,10 @@ def _function_declaration_to_tool_definition(self, function_declaration) -> Tool
187181
)
188182

189183
def _extract_tools(self, config) -> List[ToolDefinition]:
184+
try:
185+
from google.genai.types import FunctionDeclaration
186+
except ImportError:
187+
FunctionDeclaration = None
190188
tool_definitions = []
191189
tools = _get_attr(config, "tools", []) or []
192190
for tool in tools:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fixes:
2+
- |
3+
LLM Observability: Fixes an issue where certain Google GenAI LLM requests were not being traced due to importing from
4+
google.genai.types on startup.

0 commit comments

Comments
 (0)