Skip to content

Comments

Add AddMetricsConsumer helper to TelemetryConsumption#1899

Merged
MihaZupan merged 1 commit intodotnet:mainfrom
MihaZupan:metrics-consumer
Oct 19, 2022
Merged

Add AddMetricsConsumer helper to TelemetryConsumption#1899
MihaZupan merged 1 commit intodotnet:mainfrom
MihaZupan:metrics-consumer

Conversation

@MihaZupan
Copy link
Member

I am writing networking telemetry docs and it bothered me that we have very convenient helpers for ITelemetryConsumer*s, but nothing for IMetricsConsumer<T>.

So while you can write code like this for events:

services.AddTelemetryConsumer<MyTelemetryConsumer>();

you have to write this for metrics:

services.AddSingleton<IMetricsConsumer<SocketsMetrics>, MetricsConsumer>();
services.AddTelemetryListeners();

or even this if you implement multiple interfaces:

services.AddSingleton<MetricsConsumer>();
services.AddSingleton(services => (IMetricsConsumer<ForwarderMetrics>)services.GetRequiredService<MetricsConsumer>());
services.AddSingleton(services => (IMetricsConsumer<KestrelMetrics>)services.GetRequiredService<MetricsConsumer>());
services.AddSingleton(services => (IMetricsConsumer<SocketsMetrics>)services.GetRequiredService<MetricsConsumer>());
services.AddTelemetryListeners();

This PR adds AddMetricsConsumer helpers that do the same for metrics as AddTelemetryConsumer does for events.

@MihaZupan MihaZupan added this to the YARP 2.0.0 milestone Oct 17, 2022
@MihaZupan MihaZupan requested a review from Tratcher as a code owner October 17, 2022 23:36
}

var eventLevel = enableEvents ? EventLevel.Verbose : EventLevel.Critical;
var eventLevel = enableEvents ? EventLevel.Informational : EventLevel.Critical;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't change anything currently, but it can make a significant difference if we ever add debug/trace events to the existing EventSources.
Since this library only knows about the current (informational) events, it would only waste CPU on more verbose events.

If we ever want to consume more verbose events with this library, we will adjust this flag as needed.

@MihaZupan MihaZupan merged commit 6b4195a into dotnet:main Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants