Skip to content

Conversation

@stephentoub
Copy link
Member

@stephentoub stephentoub commented Oct 13, 2025

It should fail gracefully by ignoring any content it can't output telemetry for rather than throwing.

Microsoft Reviewers: Open in CodeFlow

@stephentoub stephentoub requested a review from a team as a code owner October 13, 2025 15:28
Copilot AI review requested due to automatic review settings October 13, 2025 15:28
@stephentoub stephentoub enabled auto-merge (squash) October 13, 2025 15:29
@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Oct 13, 2025
Copy link
Contributor

Copilot AI left a 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

It should fail gracefully by ignoring any content it can't output telemetry for rather than throwing.
@stephentoub stephentoub merged commit 4e71161 into dotnet:main Oct 13, 2025
6 checks passed
joperezr pushed a commit to joperezr/extensions that referenced this pull request Oct 14, 2025
…6915)

It should fail gracefully by ignoring any content it can't output telemetry for rather than throwing.
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull request Oct 21, 2025
…6915)

It should fail gracefully by ignoring any content it can't output telemetry for rather than throwing.
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull request Oct 21, 2025
…6915)

It should fail gracefully by ignoring any content it can't output telemetry for rather than throwing.
This was referenced Nov 11, 2025
This was referenced Nov 12, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants