-
Notifications
You must be signed in to change notification settings - Fork 805
Description
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
- Set up Gemini client using google-generativeai and enable OpenTelemetry instrumentation:
from opentelemetry.instrumentation.google_generativeai import GoogleGenerativeAiInstrumentor
GoogleGenerativeAiInstrumentor().instrument()
- 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,
)
- 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,
)
- 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