|
21 | 21 | from google.adk import version |
22 | 22 | from google.adk.telemetry import tracing |
23 | 23 | from google.adk.telemetry._token_usage import TokenUsage |
24 | | -from google.genai import types |
25 | 24 | from opentelemetry import metrics |
26 | 25 | from opentelemetry.semconv._incubating.attributes import gen_ai_attributes |
27 | 26 | from opentelemetry.semconv._incubating.metrics import gen_ai_metrics |
|
92 | 91 | 81.92, |
93 | 92 | ], |
94 | 93 | ) |
95 | | -_agent_request_size = meter.create_histogram( |
96 | | - "gen_ai.agent.request.size", |
97 | | - unit="By", |
98 | | - description="Size of agent requests.", |
99 | | - explicit_bucket_boundaries_advisory=[ |
100 | | - 1, |
101 | | - 4, |
102 | | - 16, |
103 | | - 64, |
104 | | - 256, |
105 | | - 1024, |
106 | | - 4096, |
107 | | - 16384, |
108 | | - 65536, |
109 | | - 262144, |
110 | | - 1048576, |
111 | | - 4194304, |
112 | | - 16777216, |
113 | | - 67108864, |
114 | | - ], |
115 | | -) |
116 | | -_agent_response_size = meter.create_histogram( |
117 | | - "gen_ai.agent.response.size", |
118 | | - unit="By", |
119 | | - description="Size of agent responses.", |
120 | | - explicit_bucket_boundaries_advisory=[ |
121 | | - 1, |
122 | | - 4, |
123 | | - 16, |
124 | | - 64, |
125 | | - 256, |
126 | | - 1024, |
127 | | - 4096, |
128 | | - 16384, |
129 | | - 65536, |
130 | | - 262144, |
131 | | - 1048576, |
132 | | - 4194304, |
133 | | - 16777216, |
134 | | - 67108864, |
135 | | - ], |
136 | | -) |
137 | 94 | _agent_workflow_steps = meter.create_histogram( |
138 | 95 | "gen_ai.agent.workflow.steps", |
139 | 96 | unit="1", |
@@ -191,28 +148,6 @@ def record_workflow_invocation_duration( |
191 | 148 | _workflow_invocation_duration.record(elapsed_s, attributes=attrs) |
192 | 149 |
|
193 | 150 |
|
194 | | -def record_agent_request_size( |
195 | | - agent_name: str, user_content: types.Content | None |
196 | | -): |
197 | | - """Records the size of the agent request.""" |
198 | | - size = _get_content_size(user_content) |
199 | | - attrs = {gen_ai_attributes.GEN_AI_AGENT_NAME: agent_name} |
200 | | - _agent_request_size.record(size, attributes=attrs) |
201 | | - |
202 | | - |
203 | | -def record_agent_response_size(agent_name: str, events: list[Event]): |
204 | | - """Records the size of the agent response by extracting content from events.""" |
205 | | - response_content: types.Content | None = None |
206 | | - for event in reversed(events): |
207 | | - if event.author == agent_name and event.content: |
208 | | - response_content = event.content |
209 | | - break |
210 | | - |
211 | | - size = _get_content_size(response_content) |
212 | | - attrs = {gen_ai_attributes.GEN_AI_AGENT_NAME: agent_name} |
213 | | - _agent_response_size.record(size, attributes=attrs) |
214 | | - |
215 | | - |
216 | 151 | def record_agent_workflow_steps(agent_name: str, events: list[Event]): |
217 | 152 | """Records the number of steps in the agent workflow by counting the number of events.""" |
218 | 153 | attrs = {gen_ai_attributes.GEN_AI_AGENT_NAME: agent_name} |
@@ -318,20 +253,6 @@ def record_client_token_usage( |
318 | 253 | _client_token_usage.record(output_token_count, attributes=output_attrs) |
319 | 254 |
|
320 | 255 |
|
321 | | -def _get_content_size( |
322 | | - content: types.Content | None, |
323 | | -) -> int: |
324 | | - if not content or not content.parts: |
325 | | - return 0 |
326 | | - size = 0 |
327 | | - for part in content.parts: |
328 | | - if part.text is not None: |
329 | | - size += len(part.text.encode("utf-8")) |
330 | | - if part.inline_data and part.inline_data.data: |
331 | | - size += len(part.inline_data.data) |
332 | | - return size |
333 | | - |
334 | | - |
335 | 256 | def _get_provider_name() -> str: |
336 | 257 | return tracing._guess_gemini_system_name() |
337 | 258 |
|
|
0 commit comments