Add openai.api.type telemetry attribute to OpenAI IChatClient implementations#7316
Merged
stephentoub merged 3 commits intomainfrom Feb 17, 2026
Merged
Add openai.api.type telemetry attribute to OpenAI IChatClient implementations#7316stephentoub merged 3 commits intomainfrom
openai.api.type telemetry attribute to OpenAI IChatClient implementations#7316stephentoub merged 3 commits intomainfrom
Conversation
Implements the OpenTelemetry semantic convention for distinguishing OpenAI API types (open-telemetry/semantic-conventions#3337). - OpenAIChatClient adds openai.api.type=chat_completions - OpenAIResponsesChatClient adds openai.api.type=responses - Both check Activity.Current for a matching "chat" span from OpenTelemetryChatClient - Added tests for both streaming and non-streaming scenarios Co-authored-by: stephentoub <[email protected]>
…sions Co-authored-by: stephentoub <[email protected]>
Copilot
AI
changed the title
[WIP] Update OpenAI IChatClient implementations with OpenTelemetry tags
Add Feb 17, 2026
openai.api.type telemetry attribute to OpenAI IChatClient implementations
stephentoub
approved these changes
Feb 17, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Implements the OpenTelemetry openai.api.type semantic attribute for OpenAI IChatClient implementations so that spans created by OpenTelemetryChatClient are annotated with the specific OpenAI API flavor being used.
Changes:
- Added a shared
OpenAIClientExtensions.AddOpenAIApiTypehelper to tag the current"chat"Activitywithopenai.api.typewhen appropriate. - Updated
OpenAIChatClientandOpenAIResponsesChatClientto tag"chat"spans withchat_completionsandresponsesrespectively (streaming and non-streaming). - Added theory tests validating the tag is emitted for both streaming and non-streaming calls via an
ActivityListener.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIClientExtensions.cs |
Adds constants + helper to set openai.api.type on the active "chat" span. |
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs |
Tags OpenTelemetry "chat" activity with chat_completions. |
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs |
Tags OpenTelemetry "chat" activity with responses. |
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIChatClientTests.cs |
Adds streaming/non-streaming coverage asserting openai.api.type=chat_completions. |
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientTests.cs |
Adds streaming/non-streaming coverage asserting openai.api.type=responses. |
tarekgh
approved these changes
Feb 17, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Implements the
openai.api.typesemantic convention from open-telemetry/semantic-conventions#3337. Each OpenAI IChatClient checks for an activeActivityfromOpenTelemetryChatClientand tags it with the API type.OpenAIClientExtensions: SharedAddOpenAIApiTypehelper that checksActivity.Currentfor a "chat" span (matchingOpenTelemetryChatClient's naming pattern) and adds theopenai.api.typetag whenIsAllDataRequestedis trueOpenAIChatClient: Tags withchat_completionsin bothGetResponseAsyncandGetStreamingResponseAsyncOpenAIResponsesChatClient: Tags withresponsesin both methodsActivityListenerThe detection pattern follows the same convention as
FunctionInvokingChatClient.CurrentActivityIsInvokeAgent—matchingDisplayNamestarting with"chat"followed by EOS or space.OpenAIAssistantsChatClientis not modified as the Assistants API is not one of the well-known enum values in the convention.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Microsoft Reviewers: Open in CodeFlow