Skip to content

Tool calls and responses not recorded in message events in opentelemetry-instrumentation-google-genaiΒ #3608

@alexmojaki

Description

@alexmojaki

AFAICT this is not addressed by #3446, which adds spans to the tool calls themselves. The events as described in https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-events/ are missing gen_ai.tool.message and the tool_calls part of the gen_ai.assistant.message event body.

For example, in https://github.com/pydantic/logfire/blob/94e0a605b6c65342650fd2c8bd5f587c3c3399d8/tests/otel_integrations/test_google_genai.py I have:

from google.genai import Client, types

client = Client()


def get_current_weather(location: str) -> str:
    """Returns the current weather.

    Args:
      location: The city and state, e.g. San Francisco, CA
    """
    return 'rainy'


response = client.models.generate_content(  # type: ignore
    model='gemini-2.0-flash-001',
    contents='What is the weather like in Boston?',
    config=types.GenerateContentConfig(
        tools=[get_current_weather],
    ),
)

and it just produces events data like this:

                        {'content': 'What is the weather like in Boston?', 'role': 'user'},
                        {
                            'index': 0,
                            'finish_reason': 'STOP',
                            'message': {'role': 'assistant', 'content': ['It is rainy in Boston, MA.\n']},
                        },

It's calling the tools, but not showing it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions