-
Notifications
You must be signed in to change notification settings - Fork 841
Add Name property to OtelMessage to store ChatMessage.AuthorName per OpenTelemetry semantic conventions #6953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…Name Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/OpenTelemetryChatClientTests.cs
Outdated
Show resolved
Hide resolved
…Logged_Async test Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for OpenTelemetry semantic conventions update by introducing a Name property to store ChatMessage.AuthorName in telemetry data. The change enables tracking of message author names in OpenTelemetry traces when present.
Key changes:
- Added nullable
Nameproperty toOtelMessageclass to capture author information - Updated message serialization logic to populate the new property from
ChatMessage.AuthorName - Enhanced test coverage to validate the
namefield appears correctly in telemetry output
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Libraries/Microsoft.Extensions.AI/ChatCompletion/OpenTelemetryChatClient.cs | Added Name property to OtelMessage class and populated it from ChatMessage.AuthorName during serialization |
| test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/OpenTelemetryChatClientTests.cs | Updated test to set AuthorName on sample messages and verify the name field is correctly included in telemetry output |
…OpenTelemetry semantic conventions (dotnet#6953) * Initial plan * Add Name property to OtelMessage and populate from ChatMessage.AuthorName Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> * Refactor: integrate AuthorName test into existing ExpectedInformationLogged_Async test Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
…OpenTelemetry semantic conventions (#6953) * Initial plan * Add Name property to OtelMessage and populate from ChatMessage.AuthorName Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> * Refactor: integrate AuthorName test into existing ExpectedInformationLogged_Async test Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Summary
This PR implements support for the OpenTelemetry semantic conventions update from open-telemetry/semantic-conventions#2944 by adding a new nullable
Nameproperty toOtelMessagethat stores the value fromChatMessage.AuthorName.Changes
Core Implementation
OpenTelemetryChatClient.cs:
Nameproperty to the privateOtelMessageclass as a nullable stringSerializeChatMessagesmethod to populateOtelMessage.NamefromChatMessage.AuthorNameThe property automatically participates in JSON serialization with snake_case naming (
name) and respects the existingJsonIgnoreCondition.WhenWritingNullsetting, ensuring null values are not included in the serialized output.Testing
OpenTelemetryChatClientTests.cs:
ExpectedInformationLogged_Asynctest to includeAuthorNameon two messagesnamefield is correctly serialized in telemetry dataExample
When a
ChatMessagehas anAuthorNameset, it will now be included in the telemetry data:Serializes to:
{ "role": "user", "name": "alice", "parts": [ { "type": "text", "content": "Hello!" } ] }Messages without
AuthorNamecontinue to work as before, with nonamefield in the output.Testing
✅ All 5 OpenTelemetryChatClient tests pass
✅ Backward compatibility maintained with existing tests
✅ Build successful across all target frameworks (net8.0, net9.0, net462, netstandard2.0)
> [!WARNING]
>
>
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Microsoft Reviewers: Open in CodeFlow