Skip to content

Commit 0840f6d

Browse files
wconti27sabrenner
andauthored
fix(tracing): add getattr checks for safety in google-adk integration (#14724)
## Description Fixes bug where `model` attribute isn't available. Adds getattr to be safer and not cause errors. ## Testing <!-- Describe your testing strategy or note what tests are included --> ## Risks <!-- Note any risks associated with this change, or "None" if no risks --> ## Additional Notes <!-- Any other information that would be helpful for reviewers --> --------- Co-authored-by: Sam Brenner <106700075+sabrenner@users.noreply.github.com>
1 parent af46ad4 commit 0840f6d

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

ddtrace/contrib/internal/google_adk/patch.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def get_version() -> str:
3434
def _traced_agent_run_async(adk, pin, wrapped, instance, args, kwargs):
3535
"""Trace the main execution of an agent (async generator)."""
3636
integration: GoogleAdkIntegration = adk._datadog_integration
37-
provider_name, model_name = extract_provider_and_model_name(instance=instance.agent.model, model_name_attr="model")
37+
agent = getattr(instance, "agent", None)
38+
model = getattr(agent, "model", None)
39+
provider_name, model_name = extract_provider_and_model_name(instance=model, model_name_attr="model")
3840

3941
span = integration.trace(
4042
pin,
@@ -79,7 +81,9 @@ async def _traced_functions_call_tool_async(adk, pin, wrapped, instance, args, k
7981
logger.warning("Unable to trace google adk live tool call, could not extract agent from tool context.")
8082
return wrapped(*args, **kwargs)
8183

82-
provider_name, model_name = extract_provider_and_model_name(instance=agent.model, model_name_attr="model")
84+
provider_name, model_name = extract_provider_and_model_name(
85+
instance=getattr(agent, "model", {}), model_name_attr="model"
86+
)
8387
instance = instance or args[0]
8488

8589
with integration.trace(
@@ -117,7 +121,9 @@ async def _traced_functions_call_tool_live(adk, pin, wrapped, instance, args, kw
117121
async for item in agen:
118122
yield item
119123

120-
provider_name, model_name = extract_provider_and_model_name(instance=agent.model, model_name_attr="model")
124+
provider_name, model_name = extract_provider_and_model_name(
125+
instance=getattr(agent, "model", {}), model_name_attr="model"
126+
)
121127

122128
with integration.trace(
123129
pin,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
google-adk: Fixes an ``AttributeError`` that could occur when tracing Google ADK agent runs, due to the agent ``model`` attribute not being defined for
5+
``SequentialAgent`` class.

0 commit comments

Comments
 (0)