Add agent call count metrics on AgentInvocation (#597) - #634
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The Towncrier changelog fragment filename does not match the PR/issue number referenced in the PR description, reducing traceability and conflicting with expected fragment naming.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds opentelemetry-util-genai support for recording agent invocation call-count metrics aligned with the GenAI semconv, so downstream instrumentations can report how many model/tool calls happened during invoke_agent.
Changes:
- Added two new metric instruments for agent call counts (
gen_ai.invoke_agent.inference_calls,gen_ai.invoke_agent.tool_calls). - Extended
AgentInvocationand the metrics recorder to carry/emitinference_callsandtool_calls(including agent name in metric attributes). - Added unit tests covering presence/absence/zero counts, error cases, and remote-agent server attributes.
File summaries
| File | Description |
|---|---|
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/instruments.py | Defines new histogram instruments for agent inference/tool call counts and exports them. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/metrics.py | Registers the new instruments and records call-count metrics when present on an invocation. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/_agent_invocation.py | Adds inference_calls / tool_calls, includes agent name in metric attributes, and records via record_agent(). |
| util/opentelemetry-util-genai/tests/test_handler_agent.py | Adds test coverage for agent call-count metric recording behavior. |
| util/opentelemetry-util-genai/.changelog/634.added | Adds a Towncrier fragment describing the new agent call-count metric support. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @@ -0,0 +1,2 @@ | |||
| Add support to track and record agent inference and tool call metrics on AgentInvocation. | |||
There was a problem hiding this comment.
Renamed the Towncrier fragment to 597.added in commit 92c520b to match the referenced issue number.
Pull request dashboard statusWaiting on the author · refreshed 2026-09-11 22:31 UTC Resolve merge conflicts. Respond to 3 review items (e.g. link a commit, explain why not, ask a follow-up): Status above doesn't look right?
|
|
/dashboard route:reviewers |
|
@dlowzzxx, this pull request was routed to reviewers. |
lmolkova
left a comment
There was a problem hiding this comment.
I believe it's blocked on https://github.com/open-telemetry/opentelemetry-python-genai/pull/616/changes, please give it a review
|
Thanks for pointing this out, @lmolkova! I have completed a thorough review of #616 (#616) and submitted an approving review. Splitting Once #616 is merged, I will rebase PR #634 to cleanly attach the |
|
/dashboard route:reviewers |
|
#616 is being merged, please rebase |
|
@dlowzzxx, this pull request was routed to reviewers. No top-level feedback was retired because the dashboard could not determine a safe command time; unresolved review threads remain open. |
…on AgentInvocation (open-telemetry#597)
92c520b to
6afb60a
Compare
|
@lmolkova Rebased onto upstream \main\ following the merge of #616. The call-count metrics (\gen_ai.invoke_agent.inference_calls\ and \gen_ai.invoke_agent.tool_calls) are now wired across \LocalAgentInvocation\ and \RemoteAgentInvocation\ via _Instruments, and the Towncrier fragment is aligned to \634.added. Full test suite and lint checks pass cleanly. /dashboard route:reviewers |
Description
Tracks and records agent call count metrics on \AgentInvocation\ (\LocalAgentInvocation\ and \RemoteAgentInvocation) in \opentelemetry-util-genai\ per OpenTelemetry Generative AI Semantic Conventions (\semantic-conventions-genai).
Per issue #597, semantic conventions define two call count histogram metrics for agent invocations:
This PR addresses the foundational sub-task of #597:
Key Changes:
Related to #597.
Type of change
How has this been tested?
uff check util/opentelemetry-util-genai: passed cleanly.
uff format --check util/opentelemetry-util-genai: passed cleanly across 72 files.
Checklist