GenAI Utils | Add agent metrics, and events #4329
Draft
etserend wants to merge 2 commits intoopen-telemetry:mainfrom
Draft
GenAI Utils | Add agent metrics, and events #4329etserend wants to merge 2 commits intoopen-telemetry:mainfrom
etserend wants to merge 2 commits intoopen-telemetry:mainfrom
Conversation
d1959e6 to
8f2f3e1
Compare
wrisa
reviewed
Mar 16, 2026
util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py
Outdated
Show resolved
Hide resolved
util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py
Outdated
Show resolved
Hide resolved
adityamehra
reviewed
Mar 16, 2026
util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py
Outdated
Show resolved
Hide resolved
util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py
Outdated
Show resolved
Hide resolved
util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py
Outdated
Show resolved
Hide resolved
util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py
Outdated
Show resolved
Hide resolved
adityamehra
reviewed
Mar 18, 2026
| attributes[error_attributes.ERROR_TYPE] = error_type | ||
|
|
||
| if duration_seconds is not None: | ||
| self._duration_histogram.record( |
There was a problem hiding this comment.
We might need to emit gen_ai.agent.duration metric to capture the agent duration and operation duration might not suffice. Is gen_ai.agent.duration part of the sem conv?
| tool_definitions: list[dict[str, Any]] | None = None | ||
|
|
||
| # Span kind: CLIENT for remote agents, INTERNAL for in-process agents | ||
| is_remote: bool = True |
There was a problem hiding this comment.
Why is the default value True? Are we assuming the invoke agents will be a remote agent call by default and not an in-process agent?
Also, SpanContext already has a field to check for is remote - https://opentelemetry.io/docs/specs/otel/trace/api/#isremote. Maybe we can use that
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
gen_ai.client.operation.durationandgen_ai.client.token.usagehistogram metrics along withgen_ai.client.inference.operation.detailslog events for agent lifecycle operations (create_agent, invoke_agent).Demo app PR: #4343
Sample metrics output:
Sample events output:
Fixes # (issue)
Type of change
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.