Skip to content

rfc(decision): Prevent duplicate AI Client Spans#155

Open
alexander-alderman-webb wants to merge 3 commits intomainfrom
rfc/prevent-duplicate-ai-client-spans
Open

rfc(decision): Prevent duplicate AI Client Spans#155
alexander-alderman-webb wants to merge 3 commits intomainfrom
rfc/prevent-duplicate-ai-client-spans

Conversation

@alexander-alderman-webb
Copy link

@alexander-alderman-webb alexander-alderman-webb commented Mar 9, 2026

@alexander-alderman-webb alexander-alderman-webb force-pushed the rfc/prevent-duplicate-ai-client-spans branch from 6f90149 to e2d49ed Compare March 9, 2026 15:15

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@nicohrubec nicohrubec Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants