-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
planned[Status] This issue is planned to be work on by ADK eng team[Status] This issue is planned to be work on by ADK eng teamtracing[Component] This issue is related to OpenTelemetry tracing[Component] This issue is related to OpenTelemetry tracing
Description
Description
When running agents on Vertex AI Agent Engine (Reasoning Engine), OpenTelemetry tracing emits warnings about invalid attribute types for LLM request/response data.
Warning Messages
WARNING: Invalid type dict for attribute 'gcp.vertex.agent.llm_request' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
WARNING: Invalid type dict for attribute 'gcp.vertex.agent.llm_response' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
Environment
- ADK Version: google-adk 1.21.0
- Platform: Vertex AI Agent Engine (Reasoning Engine)
- Python: 3.12
- Region: us-central1
Root Cause
OpenTelemetry span attributes only support primitive types (bool, str, bytes, int, float) or sequences of those types. The ADK tracing code is attempting to set gcp.vertex.agent.llm_request and gcp.vertex.agent.llm_response as dict objects, which OTEL rejects.
Expected Behavior
LLM request/response data should either be:
- Serialized to JSON string before being set as span attributes
- Set as span events instead of attributes (events support structured data)
- Logged separately rather than attached to spans
Impact
- Warnings clutter logs on every LLM call
- Tracing data for LLM requests/responses may be incomplete or missing in Cloud Trace
- Not blocking execution but reduces observability quality
Suggested Fix
In the tracing code that sets these attributes, serialize dict values to JSON strings:
import json
# Instead of:
span.set_attribute("gcp.vertex.agent.llm_request", llm_request_dict)
# Use:
span.set_attribute("gcp.vertex.agent.llm_request", json.dumps(llm_request_dict, default=str))Or use span events for structured data:
span.add_event("llm_request", attributes={"data": json.dumps(llm_request_dict, default=str)})Reproduction
- Deploy an agent to Vertex AI Agent Engine
- Send a request that triggers an LLM call
- Check Cloud Logging stderr logs for the warning messages
Related Issues
- TypeError: Object of type bytes is not JSON serializable with Gemini 3.0 Thought Signatures and google-adk v1.21.0 #4043 - Similar serialization issue with
bytestype forthought_signature
Both issues stem from ADK's telemetry not properly handling non-primitive types when setting OTEL span attributes.
Metadata
Metadata
Assignees
Labels
planned[Status] This issue is planned to be work on by ADK eng team[Status] This issue is planned to be work on by ADK eng teamtracing[Component] This issue is related to OpenTelemetry tracing[Component] This issue is related to OpenTelemetry tracing