Split invoke_agent into separate client and internal spans, and split attributes from inference hierarchy#3514
Conversation
Add all attributes from the invoke_agent client span (per PR open-telemetry#3514) to the server span, including token usage with aggregation notes, inference request parameters, conversation id, content attributes, and tool definitions.
invoke_agent into separate client and internal spans, and split attributes from inference hierarchy
…from-inference # Conflicts: # docs/gen-ai/gen-ai-agent-spans.md
|
@trask If span kind INTERNAL does not have |
eternalcuriouslearner
left a comment
There was a problem hiding this comment.
Great stuff!! It's a step in forward direction for providing better transparency in understanding agents. I left few comments to enhance clarity around the documentation. Thanks for this @trask.
Would this require any inference client being used by agent to have tracing enabled assuming those client libs emit traces? For cases where I use openai client lib to call LLM but I do not have |
I believe so. This feels more like an implementation limitation than a semantic conventions one. Not every agent invocation exposes token usage in its return value, especially in-process ones. So if the inference client itself isn’t instrumented/traced, instrumentation usually has no cheap way to accurately capture the agent’s token usage. |
Providing information like token usage (not limited to it) should be responsibility of the agent framework rather than instrumentation lib in my opinion. For example, OpenAI Responses API does it no matter whether it is instrumented or no. Instrumentation libs should definitely capture it. |
Agree with you. So in any case, we should do our best to count token usage in |
a few options:
|
I brought back token usage on internal spans to make this PR easier to move forward (as it was intended to mostly be a mechanical change) and we can discuss that issues separately. |
bb1dc68
Fixes #2632
Changes to the existing
invoke_agentclient span:gen_ai.response.idgen_ai.response.modelgen_ai.agent.versionserver.addressrequirement level simplified fromrecommended: when span kind is CLIENTtorecommended(since the span is always client kind now)New
invoke_agentinternal span (span.gen_ai.invoke_agent.internal):The internal span is for in-process agents (e.g., LangChain, CrewAI). Compared to the client span, the internal span:
span_kind: internal(vsclient)server.addressorserver.port