Update the root Otel span to be an invoke_agentspan#45033
Update the root Otel span to be an invoke_agentspan#45033luigiw wants to merge 2 commits intoAzure:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors OpenTelemetry tracing to align with the "invoke_agent" semantic convention. The changes extract agent name/ID retrieval into a reusable helper function and update the root span to follow GenAI semantic conventions.
Changes:
- Refactored agent name/ID extraction into a reusable
get_agent_name()helper function - Updated span naming from
HostedAgents-{response_id}toinvoke_agent {agent_name} - Changed span kind from SERVER to CLIENT and added GenAI semantic convention attributes
| name=span_name, | ||
| attributes=ctx, | ||
| kind=trace.SpanKind.SERVER, | ||
| kind=trace.SpanKind.CLIENT, |
There was a problem hiding this comment.
The span kind has been changed from SERVER to CLIENT, but this endpoint is receiving HTTP requests, which indicates it should use SpanKind.SERVER according to OpenTelemetry semantic conventions. SpanKind.CLIENT is typically used for outbound calls the service makes, not for handling incoming requests. This is a server endpoint (runs_endpoint) handling incoming POST requests to /runs or /responses. Unless this represents the client-side invocation of an agent (not the HTTP server receiving the request), this should remain SpanKind.SERVER.
| kind=trace.SpanKind.CLIENT, | |
| kind=trace.SpanKind.SERVER, |
| Extract the agent name and agent id from an AgentRunContext. | ||
|
|
||
| :param agent_run_context: The AgentRunContext instance to extract from. | ||
| :type agent_run_context: AgentRunContext | ||
| :return: Tuple of (agent_name, agent_id). Agent id is formatted as "name:version". |
There was a problem hiding this comment.
The docstring uses the term "Agent id" in the description, but the parameter name is "agent_run_context". For consistency with other docstrings in the codebase and clarity, consider rephrasing to "Extract the agent name and agent ID from an AgentRunContext." (capitalizing "ID" to match the parameter description).
| Extract the agent name and agent id from an AgentRunContext. | |
| :param agent_run_context: The AgentRunContext instance to extract from. | |
| :type agent_run_context: AgentRunContext | |
| :return: Tuple of (agent_name, agent_id). Agent id is formatted as "name:version". | |
| Extract the agent name and agent ID from an AgentRunContext. | |
| :param agent_run_context: The AgentRunContext instance to extract from. | |
| :type agent_run_context: AgentRunContext | |
| :return: Tuple of (agent_name, agent_id). Agent ID is formatted as "name:version". |
|
|
||
| :param agent_run_context: The AgentRunContext instance to extract from. | ||
| :type agent_run_context: AgentRunContext | ||
| :return: Tuple of (agent_name, agent_id). Agent id is formatted as "name:version". |
There was a problem hiding this comment.
The docstring states "Agent id is formatted as 'name:version'" but should be "Agent ID is formatted as 'name:version'" for consistency with standard capitalization of "ID" in technical documentation.
| :return: Tuple of (agent_name, agent_id). Agent id is formatted as "name:version". | |
| :return: Tuple of (agent_name, agent_id). Agent ID is formatted as "name:version". |
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
Description
Please add an informative description that covers that changes made by the pull request and link all relevant issues.
If an SDK is being regenerated based on a new API spec, a link to the pull request containing these API spec changes should be included above.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines