rfc(decision): Prevent duplicate AI Client Spans#155
Open
alexander-alderman-webb wants to merge 3 commits intomainfrom
Open
rfc(decision): Prevent duplicate AI Client Spans#155alexander-alderman-webb wants to merge 3 commits intomainfrom
alexander-alderman-webb wants to merge 3 commits intomainfrom
Conversation
6f90149 to
e2d49ed
Compare
nicohrubec
reviewed
Mar 10, 2026
|
|
||
| Many statistics displayed in the AI Agents Insights module are based on AI Client Spans. Statistics, including the total incurred cost, require all model calls to be instrumented with AI Client Spans exactly once. Model calls initiated by agents are always instrumented in agent libraries to support users of an agent library with a model provider not yet supported by the corresponding SDK. Conversely, "low-level" libraries of model providers are also instrumented with AI Client Spans to support users who call models outside of a supported agent framework. | ||
|
|
||
| Users of a supported agent framework with a supported model provider therefore generate two AI Client Spans, resulting in biased statistics in the AI Agents Insights module. |
Member
There was a problem hiding this comment.
Might be helpful here to give an example of what you mean by biased statistics (e.g. double counting of tokens)
|
|
||
| #### Pros | ||
|
|
||
| More information used to populate the attributes of AI Client Spans is available in the client library than in the agent library abstraction. |
Member
There was a problem hiding this comment.
Suggested change
| More information used to populate the attributes of AI Client Spans is available in the client library than in the agent library abstraction. | |
| In some cases more information used to populate the attributes of AI Client Spans is available in the client library than in the agent library abstraction. |
nit but not sure if this is universally true so I'd phrase this less definitive
| └── API call | ||
| ``` | ||
|
|
||
| Some data exposed by the client library is not available at the agent's model abstraction level. For example, the concrete response model used to populate the `gen_ai.response.model` attribute is always available in the `openai` package, but never returned by the `Model` abstraction used by agents in the `openai-agents` package. |
Member
There was a problem hiding this comment.
Suggested change
| Some data exposed by the client library is not available at the agent's model abstraction level. For example, the concrete response model used to populate the `gen_ai.response.model` attribute is always available in the `openai` package, but never returned by the `Model` abstraction used by agents in the `openai-agents` package. | |
| In some cases data exposed by the client library is not available at the agent's model abstraction level. For example, the concrete response model used to populate the `gen_ai.response.model` attribute is always available in the `openai` package, but never returned by the `Model` abstraction used by agents in the `openai-agents` package. |
| Disabling spans at the client library level results in a loss of information when the agent library's abstractions expose less information about model calls, and there is no mechanism to capture information from the client library. | ||
|
|
||
| Additionally, since the model abstraction used by an agent may contain user-defined code, there can be spans in between the AI Client Spans for the agent and client library. The parent-aware disabling only applies if there are no spans in between AI Client Spans in the trace hierarchy. | ||
|
|
Member
There was a problem hiding this comment.
From our (js) side the most important drawback is that this solution doesn't work for our langchain use case
|
|
||
| #### Cons | ||
|
|
||
| The solution introduces complexity to the SDK. An integration would mutate the attributes set on a span created by another integration when the agent and client libraries are both instrumented. |
Member
There was a problem hiding this comment.
This is only true for the "AI Client Scope" case right? For the boolean case I think this is only marginally more complex than the parent solution
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.
Rendered RFC