Skip to content

[BUG]: dd-trace-py is unable to capture traces/spans when using Google ADK function tools #15174

@NclsL

Description

@NclsL

Tracer Version(s)

3.18.0

Python Version(s)

3.13.8

Pip Version(s)

21.2.4

Bug Report

See reproduction code, we're using function tool and pass it to the Agent as tool.

I assume ddtrace is expecting these 2 attributes name and description, but as they're not available it leads to errors.

Reproduction Code

import os
from typing import Any
from ddtrace.llmobs import LLMObs
from google.adk.agents import Agent
from google.adk.runners import Runner, types
from google.adk.sessions import InMemorySessionService


def get_weather(city: str) -> dict[str, Any]:
    """Retrieves the current weather report for a specified city.

    Args:
        city (str): The name of the city for which to retrieve the weather report.

    Returns:
        dict: status and result or error msg.
    """
    if city.lower() == "new york":
        return {
            "status": "success",
            "report": (
                "The weather in New York is sunny with a temperature of 25 degrees"
                " Celsius (77 degrees Fahrenheit)."
            ),
        }
    else:
        return {
            "status": "error",
            "error_message": f"Weather information for '{city}' is not available.",
        }


async def main() -> None:
    LLMObs.enable(
        ml_app="app_name",
        api_key="fill_in",
        site="fill_in",
        agentless_enabled=True    
    )

    os.environ["GOOGLE_CLOUD_PROJECT"] = "fill_in"
    os.environ["GOOGLE_CLOUD_LOCATION"] = "fill_in"
    os.environ["GOOGLE_GENAI_USE_VERTEXAI"] = "true"

    agent = Agent(
        name="weather_agent",
        model="gemini-2.0-flash",
        description="Agent to answer questions about the weather in a city.",
        instruction=(
            "Always provide the weather details in a friendly and informative manner"
        ),
        tools=[get_weather],
    )

    session_service = InMemorySessionService()
    runner = Runner(
        app_name="app_name",
        agent=agent,
        session_service=session_service,
    )

    session = await session_service.create_session(app_name="app_name", user_id="test_user")

    message = types.Content(
        parts=[types.Part(text="What's the weather like in New York?")], role="user")

    events = [
        event
        async for event in runner.run_async(
            session_id=session.id,
            user_id="test_user",
            new_message=message,
        )
    ]

    response = "No response"
    if events:
        for event in reversed(events):
            content = getattr(event, "content", None)
            if content and hasattr(content, "parts"):
                text_parts = [
                    p.text for p in content.parts if hasattr(p, "text")]
                if text_parts:
                    response = "".join(text_parts)
                    break

    print(f"\nResponse: {response}\n")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Error Logs

Error extracting LLMObs fields for span <Span(id=redacted,trace_id=redacted,parent_id=None,name=google_adk.request)>, likely due to malformed data
Traceback (most recent call last):
  File "/app/.venv/lib/python3.13/site-packages/ddtrace/llmobs/_integrations/base.py", line 105, in llmobs_set_tags
    self._llmobs_set_tags(span, args, kwargs, response, operation)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.13/site-packages/ddtrace/llmobs/_integrations/google_adk.py", line 46, in _llmobs_set_tags
    self._llmobs_set_tags_agent(span, args, kwargs, response)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.13/site-packages/ddtrace/llmobs/_integrations/google_adk.py", line 66, in _llmobs_set_tags_agent
    self._tag_agent_manifest(span, kwargs, agent_instance)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.13/site-packages/ddtrace/llmobs/_integrations/google_adk.py", line 130, in _tag_agent_manifest
    manifest["tools"] = self._get_agent_tools(getattr(agent, "tools", []))
                        ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.13/site-packages/ddtrace/llmobs/_integrations/google_adk.py", line 157, in _get_agent_tools
    return [{"name": tool.name, "description": tool.description} for tool in tools]
                     ^^^^^^^^^
AttributeError: 'function' object has no attribute 'name'

Libraries in Use

ddtrace>=3.18.0,
google-adk==1.18.0

Operating System

MacOS Tahoe 26.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions