Skip to content

Commit bd33c6c

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix-thought-signature-pruning
2 parents add107b + 68a7803 commit bd33c6c

8 files changed

Lines changed: 232 additions & 152 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,

src/google/adk/telemetry/node_tracing.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,6 @@ def _use_invoke_workflow_span(
186186
# The flag rides along the otel_context propagated to child nodes, so nested
187187
# workflows see it set.
188188
nested = bool(context_api.get_value(_ENTRYPOINT_WORKFLOW_KEY, otel_context))
189-
if not nested:
190-
otel_context = context_api.set_value(
191-
_ENTRYPOINT_WORKFLOW_KEY, True, otel_context
192-
)
193189
attributes: dict[str, AttributeValue] = {
194190
GEN_AI_OPERATION_NAME: "invoke_workflow",
195191
GEN_AI_CONVERSATION_ID: conversation_id,
@@ -207,11 +203,14 @@ def _use_invoke_workflow_span(
207203
start_s = time.monotonic()
208204
workflow_span: Span | None = None
209205
try:
210-
with tracer.start_as_current_span(
211-
name=span_name,
212-
attributes=attributes,
213-
context=otel_context,
214-
) as span:
206+
with (
207+
tracer.start_as_current_span(
208+
name=span_name,
209+
attributes=attributes,
210+
context=otel_context,
211+
) as span,
212+
_mark_nested_workflows(),
213+
):
215214
workflow_span = span
216215
yield span
217216
finally:
@@ -221,3 +220,14 @@ def _use_invoke_workflow_span(
221220
nested=nested,
222221
error=sys.exc_info()[1],
223222
)
223+
224+
225+
@contextmanager
226+
def _mark_nested_workflows() -> Iterator[None]:
227+
token = context_api.attach(
228+
context_api.set_value(_ENTRYPOINT_WORKFLOW_KEY, True)
229+
)
230+
try:
231+
yield
232+
finally:
233+
context_api.detach(token)

0 commit comments

Comments
 (0)