-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[API Proposal]: HttpClientFactory AddMetricsEnrichment #88460
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsBackground 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. I expect this feature would be implemented by registering an internal http handler with the client factory. The handler just calls API Proposalnamespace Microsoft.Extensions.DependencyInjection;
public static class HttpClientBuilderExtensions
{
public static IHttpClientBuilder AddMetricsEnrichment(this IHttpClientBuilder builder, Action<HttpMetricsEnrichmentContext> callback);
} API Usageservices.AddHttpClient("my-cool-client")
.AddHttpMessageHandler<CustomHttpHandler>()
.AddMetricsEnrichment(context =>
{
var status = context.Response.Headers.GetValue("x-status");
context.AddCustomTag("x-status", status);
}); Alternative DesignsNo response RisksNo response
|
Triage: as discussed with @JamesNK offline, this is a nice-to-have and not critical for .NET 8. Even if dotnet/extensions would need to implement this for enrichment on their side, it is going to be straightforward and wouldn't need a public API. Moving to Future. |
Will it be possible to also disable metrics on individual named http clients? I have a use case where I am only interested in metrics on a specific named http client of my application. I would like to not see the metrics of other http clients. |
@davidroth that's a good point. |
When it comes to the .NET libraries, we do provide the infrastructure to enable this: it is possible to initialize However, to make this useful in practice, collection/exporter libaries (the stuff that subscribes to these callbacks) need to expose APIs for filtering (eg. to drop recordings for a specific meter or factory). @davidroth what do you use for collection? @vishweshbankwar is there such a filter mechanism in opentelemetry-dotnet? |
That was my first thought, but what should such "no-op" factory return upon the runtime/src/libraries/System.Net.Http/src/System/Net/Http/Metrics/MetricsHandler.cs Line 22 in 7269f90
It seems that the returned meter instance should be some kind of mock as well? But |
It should return a functional IMO this should be implemented by the consumers of that event, eg. in collection libraries like Prometheus Exporter. |
Is this correct that the nesting goes as: Then I really don't understand how can I differentiate between several HttpClients and say "only include this one"... 🤔 Because I don't have any controls over neither Meter name, nor Instrument names... So when I enable the instrument, e.g. For comparison -- I know it's a completely different thing, but e.g. default
|
Given an Ofc, this is complicated, and assumes that Prometheus Exporter (or other collection libraries) have ways to customize the filtering for their InstrumentPublished implementations. If filtering metrics by originating |
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:
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
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: