-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-Extensions-HttpClientFactory
Milestone
Description
Background and motivation
.NET 8 adds metrics and enrichment support to HttpClient. See #86281
This API proposal is for a new HttpClientFactory API. It's designed to make it easier to combine enrichment with the factory.
Right now, there isn't an ask for this feature. However:
- It is a low-cost change that makes enrichment easy to use with the client factory.
- People who want to combine enrichment with HttpClientFactory could use this extension method. Reusing this method would save dotnet/extensions from having to implement this feature internally.
I expect this feature will be implemented by registering an internal http handler with the client factory. The handler just calls HttpMetricsEnrichmentContext.AddCallback with the callback passed to the extension method.
API Proposal
namespace Microsoft.Extensions.DependencyInjection;
public static class HttpClientBuilderExtensions
{
public static IHttpClientBuilder AddMetricsEnrichment(
this IHttpClientBuilder builder,
Action<HttpMetricsEnrichmentContext> callback);
}API Usage
services.AddHttpClient("my-cool-client")
.AddHttpMessageHandler<CustomHttpHandler>()
.AddMetricsEnrichment(context =>
{
var status = context.Response.Headers.GetValue("x-status");
context.AddCustomTag("x-status", status);
});Alternative Designs
No response
Risks
No response
WeihanLi
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-Extensions-HttpClientFactory