-
Notifications
You must be signed in to change notification settings - Fork 841
Fix OpenTelemetryChatClient failing on unknown content types #6915
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
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 fixes a bug in OpenTelemetryChatClient where it would fail when encountering unknown or non-serializable AI content types. Instead of throwing exceptions, the client now gracefully handles these cases by attempting to serialize unknown content types and ignoring any that can't be serialized.
Key Changes
- Modified the serialization logic to handle unknown content types gracefully with try-catch protection
- Added support for custom JSON serializer options when processing unknown content types
- Added comprehensive test coverage for the new graceful failure behavior
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Libraries/Microsoft.Extensions.AI/ChatCompletion/OpenTelemetryChatClient.cs | Enhanced SerializeChatMessages method to handle unknown content types gracefully and pass custom serializer options |
| test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/OpenTelemetryChatClientTests.cs | Added test case to verify unknown content types are handled without throwing exceptions |
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/OpenTelemetryChatClient.cs
Show resolved
Hide resolved
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/OpenTelemetryChatClientTests.cs
Show resolved
Hide resolved
It should fail gracefully by ignoring any content it can't output telemetry for rather than throwing.
6b501f5 to
25685eb
Compare
…6915) It should fail gracefully by ignoring any content it can't output telemetry for rather than throwing.
…6915) It should fail gracefully by ignoring any content it can't output telemetry for rather than throwing.
…6915) It should fail gracefully by ignoring any content it can't output telemetry for rather than throwing.
It should fail gracefully by ignoring any content it can't output telemetry for rather than throwing.
Microsoft Reviewers: Open in CodeFlow