Skip to content

BaseModel.model_dump() called on class instead of instance in opentelemetry-instrumentation-google-genai #3596

@ashaydiyan

Description

@ashaydiyan

Describe your environment

No response

What happened?

When enabling the GoogleGenAiSdkInstrumentor from the opentelemetry-instrumentation-google-genai package (v0.2b0), an exception is raised during the execution of generate_content() using the google-genai SDK (v1.21.1) with a Pydantic response schema (pydantic v2.11.7).

The root cause appears to be that the instrumentation incorrectly calls .model_dump() on a Pydantic class rather than an instance, resulting in a TypeError.

Steps to Reproduce

  1. Set up Gemini client using google-generativeai and enable OpenTelemetry instrumentation:
from opentelemetry.instrumentation.google_generativeai import GoogleGenerativeAiInstrumentor

GoogleGenerativeAiInstrumentor().instrument()
  1. Use a structured response_schema with GenerateContentConfig, like a Pydantic model.
generation_config_with_thinking = GenerateContentConfig(
                    temperature=self.temperature,
                    response_mime_type="application/json",
                    response_schema=SomePydanticModel,
            
                )
  1. Execute an async generate_content() call via:
response = await self.client.aio.models.generate_content(
    model=self.model,
    contents=content,
    config=generation_config_with_thinking,
)
  1. You’ll see the following error:
    TypeError: BaseModel.model_dump() missing 1 required positional argument: 'self'

Expected Result

The instrumentation should safely handle all supported response schemas without interfering with the normal execution of generate_content(). Specifically, it should validate and inspect Pydantic models without causing runtime exceptions, ensuring full compatibility with structured schema-based responses.

Actual Result

When calling generate_content() with a Pydantic schema and OpenTelemetry instrumentation enabled, the application fails with the following error:
TypeError: BaseModel.model_dump() missing 1 required positional argument: 'self'

Additional context

No response

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions