Skip to content

Commit 68a7803

Browse files
RKestcopybara-github
authored andcommitted
chore(telemetry): remove gen_ai.agent.workflow.steps metric
Semconv PR for this metric in: open-telemetry/semantic-conventions-genai#203 Was replaced by `gen_ai.invoke_agent.{inference,tool}_calls` metrics in: open-telemetry/semantic-conventions-genai#336 We're hence removing the non-standard and less defined `gen_ai.agent.workflow.steps` metric. Co-authored-by: Max Ind <maxind@google.com> PiperOrigin-RevId: 943154162
1 parent 20197de commit 68a7803

7 files changed

Lines changed: 0 additions & 105 deletions

File tree

src/google/adk/telemetry/_instrumentation.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ def record_llm_response(
125125
def _record_agent_metrics(
126126
agent_name: str,
127127
elapsed_s: float,
128-
events: object,
129128
caught_error: Exception | None,
130129
) -> None:
131130
try:
@@ -134,7 +133,6 @@ def _record_agent_metrics(
134133
elapsed_s,
135134
caught_error,
136135
)
137-
_metrics.record_agent_workflow_steps(agent_name, events)
138136
except Exception: # pylint: disable=broad-exception-caught
139137
logger.exception("Failed to record agent metrics for agent %s", agent_name)
140138

@@ -196,7 +194,6 @@ async def record_agent_invocation(
196194
_record_agent_metrics(
197195
agent.name,
198196
_metrics.get_elapsed_s(span, start_time),
199-
getattr(getattr(ctx, "session", None), "events", []),
200197
caught_error,
201198
)
202199
_flush_invoke_agent_metrics(tel_ctx, agent.name)

src/google/adk/telemetry/_metrics.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from opentelemetry.semconv.attributes import error_attributes
2828

2929
if TYPE_CHECKING:
30-
from google.adk.events.event import Event
3130
from google.adk.models.llm_request import LlmRequest
3231
from google.adk.models.llm_response import LlmResponse
3332
from opentelemetry.trace import Span
@@ -91,24 +90,6 @@
9190
81.92,
9291
],
9392
)
94-
_agent_workflow_steps = meter.create_histogram(
95-
"gen_ai.agent.workflow.steps",
96-
unit="1",
97-
description="Length of agentic workflow (# of events).",
98-
explicit_bucket_boundaries_advisory=[
99-
1,
100-
2,
101-
4,
102-
8,
103-
16,
104-
32,
105-
64,
106-
128,
107-
256,
108-
512,
109-
1024,
110-
],
111-
)
11293
_client_operation_duration = (
11394
gen_ai_metrics.create_gen_ai_client_operation_duration(meter)
11495
)
@@ -198,13 +179,6 @@ def record_invoke_agent_tool_calls(agent_name: str, count: int) -> None:
198179
_invoke_agent_tool_calls.record(count, attributes=attrs)
199180

200181

201-
def record_agent_workflow_steps(agent_name: str, events: list[Event]):
202-
"""Records the number of steps in the agent workflow by counting the number of events."""
203-
attrs = {gen_ai_attributes.GEN_AI_AGENT_NAME: agent_name}
204-
count = sum(1 for event in events if event.author == agent_name)
205-
_agent_workflow_steps.record(count, attributes=attrs)
206-
207-
208182
def record_tool_execution_duration(
209183
tool_name: str,
210184
tool_type: str,

tests/unittests/telemetry/functional_node_test_cases.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,9 +2742,6 @@
27422742
value=NON_DETERMINISTIC,
27432743
),
27442744
}),
2745-
"gen_ai.agent.workflow.steps": frozenset({
2746-
MetricPoint(attributes={"gen_ai.agent.name": AGENT_NAME}, value=3),
2747-
}),
27482745
"gen_ai.client.operation.duration": frozenset({
27492746
MetricPoint(
27502747
attributes={
@@ -2802,9 +2799,6 @@
28022799
value=NON_DETERMINISTIC,
28032800
),
28042801
}),
2805-
"gen_ai.agent.workflow.steps": frozenset({
2806-
MetricPoint(attributes={"gen_ai.agent.name": AGENT_NAME}, value=3),
2807-
}),
28082802
"gen_ai.client.operation.duration": frozenset({
28092803
MetricPoint(
28102804
attributes={

tests/unittests/telemetry/functional_test_cases.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,9 +2291,6 @@
22912291
value=NON_DETERMINISTIC,
22922292
),
22932293
}),
2294-
"gen_ai.agent.workflow.steps": frozenset({
2295-
MetricPoint(attributes={"gen_ai.agent.name": AGENT_NAME}, value=3),
2296-
}),
22972294
"gen_ai.client.operation.duration": frozenset({
22982295
MetricPoint(
22992296
attributes={
@@ -2332,9 +2329,6 @@
23322329
value=NON_DETERMINISTIC,
23332330
),
23342331
}),
2335-
"gen_ai.agent.workflow.steps": frozenset({
2336-
MetricPoint(attributes={"gen_ai.agent.name": AGENT_NAME}, value=3),
2337-
}),
23382332
"gen_ai.client.operation.duration": frozenset({
23392333
MetricPoint(
23402334
attributes={

tests/unittests/telemetry/functional_test_helpers.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,6 @@ class HistogramSpec(NamedTuple):
314314
attr="_tool_execution_duration",
315315
metric_name="gen_ai.execute_tool.duration",
316316
),
317-
HistogramSpec(
318-
module=_metrics,
319-
attr="_agent_workflow_steps",
320-
metric_name="gen_ai.agent.workflow.steps",
321-
),
322317
HistogramSpec(
323318
module=_metrics,
324319
attr="_client_operation_duration",

tests/unittests/telemetry/test_instrumentation.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
import time
1818
from unittest import mock
1919

20-
from google.adk.telemetry import _instrumentation
2120
from google.adk.telemetry import _metrics
2221
from opentelemetry import trace
23-
import pytest
2422

2523

2624
def test_get_elapsed_s_span_none():
@@ -82,36 +80,3 @@ def test_get_elapsed_s_span_non_int_end():
8280
with mock.patch("time.monotonic", return_value=12.0):
8381
elapsed = _metrics.get_elapsed_s(mock_span, start_time)
8482
assert elapsed == 2.0
85-
86-
87-
@pytest.mark.asyncio
88-
async def test_record_agent_invocation_tolerates_minimal_context():
89-
"""Tolerates context-likes that lack session.
90-
91-
Test doubles, partial migrations, and external embedders can pass an
92-
InvocationContext-like object with a `session` that has no `events`
93-
attribute. The telemetry path must not raise AttributeError on the
94-
metrics call in those cases.
95-
"""
96-
agent = mock.MagicMock()
97-
agent.name = "test_agent"
98-
# Bare object without `session`.
99-
bare_ctx = object()
100-
101-
with (
102-
mock.patch.object(
103-
_instrumentation, "_record_agent_metrics"
104-
) as mock_record,
105-
mock.patch.object(_instrumentation, "tracing") as mock_tracing,
106-
):
107-
mock_tracing.tracer.start_as_current_span.return_value.__enter__.return_value = mock.MagicMock(
108-
spec=trace.Span
109-
)
110-
async with _instrumentation.record_agent_invocation(bare_ctx, agent):
111-
pass
112-
113-
mock_record.assert_called_once()
114-
call_args = mock_record.call_args
115-
# positional: (agent_name, elapsed_s, events, caught_error)
116-
assert call_args.args[0] == "test_agent"
117-
assert call_args.args[2] == [] # events default

tests/unittests/telemetry/test_metrics.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ def _mock_meter_setup(monkeypatch):
2929
agent_duration_hist = mock.MagicMock(spec=metrics.Histogram)
3030
workflow_duration_hist = mock.MagicMock(spec=metrics.Histogram)
3131
tool_duration_hist = mock.MagicMock(spec=metrics.Histogram)
32-
steps_hist = mock.MagicMock(spec=metrics.Histogram)
3332
client_duration_hist = mock.MagicMock(spec=metrics.Histogram)
3433
client_token_usage_hist = mock.MagicMock(spec=metrics.Histogram)
3534

3635
agent_duration_hist.name = "agent_invocation_duration"
3736
workflow_duration_hist.name = "workflow_invocation_duration"
3837
tool_duration_hist.name = "tool_execution_duration"
39-
steps_hist.name = "agent_workflow_steps"
4038
client_duration_hist.name = "client_operation_duration"
4139
client_token_usage_hist.name = "client_token_usage"
4240

@@ -47,8 +45,6 @@ def create_histogram_side_effect(name, **_kwargs):
4745
return workflow_duration_hist
4846
elif name == "gen_ai.execute_tool.duration":
4947
return tool_duration_hist
50-
elif name == "gen_ai.agent.workflow.steps":
51-
return steps_hist
5248
elif name == "gen_ai.client.operation.duration":
5349
return client_duration_hist
5450
elif name == "gen_ai.client.token.usage":
@@ -66,7 +62,6 @@ def create_histogram_side_effect(name, **_kwargs):
6662
_metrics, "_workflow_invocation_duration", workflow_duration_hist
6763
)
6864
monkeypatch.setattr(_metrics, "_tool_execution_duration", tool_duration_hist)
69-
monkeypatch.setattr(_metrics, "_agent_workflow_steps", steps_hist)
7065
monkeypatch.setattr(
7166
_metrics, "_client_operation_duration", client_duration_hist
7267
)
@@ -77,7 +72,6 @@ def create_histogram_side_effect(name, **_kwargs):
7772
"agent_duration": agent_duration_hist,
7873
"workflow_duration": workflow_duration_hist,
7974
"tool_duration": tool_duration_hist,
80-
"steps": steps_hist,
8175
"client_duration": client_duration_hist,
8276
"client_token_usage": client_token_usage_hist,
8377
}
@@ -145,24 +139,6 @@ def test_record_workflow_invocation_duration_nested_with_error(
145139
assert kwargs["attributes"]["error.type"] == "ValueError"
146140

147141

148-
def test_record_agent_workflow_steps(mock_meter_setup):
149-
"""Tests record_agent_workflow_steps records correctly."""
150-
_metrics.record_agent_workflow_steps(
151-
"test_agent",
152-
[
153-
mock.MagicMock(author="test_agent"),
154-
mock.MagicMock(author="test_agent"),
155-
mock.MagicMock(author="other_agent"),
156-
],
157-
)
158-
steps_hist = mock_meter_setup["steps"]
159-
steps_hist.record.assert_called_once()
160-
args, kwargs = steps_hist.record.call_args
161-
assert args[0] == 2
162-
want_attributes = {"gen_ai.agent.name": "test_agent"}
163-
assert kwargs["attributes"] == want_attributes
164-
165-
166142
def test_record_tool_execution_duration(mock_meter_setup):
167143
"""Tests record_tool_execution_duration records correctly."""
168144
_metrics.record_tool_execution_duration(

0 commit comments

Comments
 (0)