Skip to content

fix(telemetry): mark invoke_agent span as error on asyncio cancellation (#8524) - #8525

Open
Abdulrehman1978 wants to merge 1 commit into
google:mainfrom
Abdulrehman1978:fix/invoke-agent-cancelled-span
Open

Abdulrehman1978 wants to merge 1 commit into
google:mainfrom
Abdulrehman1978:fix/invoke-agent-cancelled-span

Conversation

@Abdulrehman1978

Copy link
Copy Markdown

Summary

When an agent invocation is cancelled via asyncio.CancelledError, _recording_span and record_agent_invocation in src/google/adk/telemetry/_instrumentation.py previously caught only Exception, leaving invoke_agent <name> spans with StatusCode.UNSET and omitting error.type from both the span and gen_ai.agent.invocation.duration.

Fixes #8524

Changes

  • Catch (Exception, asyncio.CancelledError) in _recording_span and record_agent_invocation (src/google/adk/telemetry/_instrumentation.py) so asyncio.CancelledError is recorded on invoke_agent spans and passed to _record_agent_metrics, while GeneratorExit remains unmarked.
  • Widen caught_error / error type annotations to BaseException | None in _record_agent_metrics and record_agent_invocation_duration (src/google/adk/telemetry/_metrics.py).
  • Add regression tests in tests/unittests/telemetry/test_instrumentation.py:
    • test_record_agent_invocation_marks_cancelled_span_as_error
    • test_record_agent_invocation_does_not_mark_generator_exit_as_error

Testing

  • pytest tests/unittests/telemetry/test_instrumentation.py tests/unittests/telemetry/test_metrics.py -q (170 passed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

invoke_agent span isn't marked as an error when the invocation is cancelled

1 participant