Skip to content

Extend HTTP request failure logging to handle general exceptions - #135674

Open
makazeu wants to merge 2 commits into
dotnet:mainfrom
makazeu:fix-httpclientfactory-failure-logging
Open

makazeu wants to merge 2 commits into
dotnet:mainfrom
makazeu:fix-httpclientfactory-failure-logging

Conversation

@makazeu

@makazeu makazeu commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Default IHttpClientFactory logging currently records failures only for HttpRequestException, leaving other handler exceptions without a corresponding failure event.

This change extends both default logging handlers to record non-cancellation exceptions and rethrow them unchanged. The outer handler records failures escaping the pipeline; the inner handler records only failures from the portion it wraps. Existing event IDs, names, categories, levels, and redaction behavior are preserved.

OperationCanceledException and its subclasses remain excluded. HTTP error responses and failures while reading response content after the pipeline returns retain their existing treatment. No public API is added.

Testing

Expanded the existing failure-logging test to 26 cases covering synchronous/asynchronous sends, early rejection, primary-handler failures, cancellation, event metadata, and exception identity.

  • Before the fix: 8 new non-HTTP failure cases failed due to missing logs; the other 18 passed.
  • After the fix: the full Microsoft.Extensions.Http suite passed 210/210 tests on WSL/Linux x64.
  • All supported product target frameworks built with zero warnings or errors. Windows/.NET Framework execution tests were not run.

Resolves #135199

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 13, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

This branch has not been deployed

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

Labels

area-Extensions-HttpClientFactory community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Log non-HTTP handler exceptions in default IHttpClientFactory logging

1 participant