opentelemetry-dotnet-contrib
opentelemetry-dotnet-contrib copied to clipboard
DI support for configuring EventCounters
Issue with OpenTelemetry.Instrumentation.EventCounters
Is this a feature request or a bug?
- [x ] Feature Request
- [ ] Bug
What is the expected behavior?
- Event counters instrumentation can be enabled when using DI based APIs i.e. services.AddOpenTelemetryMetrics(...) and support providing options via IConfigurationSection
What do you expect to see?
-
AddEventCountersInstrumentationwork withIDeferredMeterProviderBuilder - Another overload
public static MeterProviderBuilder AddEventCountersInstrumentation(this MeterProviderBuilder builder, IConfigurationSection)
What is the actual behavior?
Today it only works for non DI mode. Options can't be provided directly via configuration
Additional Context
Add any other context about the feature request here.
Just FYI 1.4.0 SDK is introducing an updated pattern which allows better integration than what IDeferredMeterProviderBuilder can provide. I would recommend using OpenTelemetry.Exporter.Prometheus.AspNetCore as a guide for this effort.
Instead of...
public static MeterProviderBuilder AddEventCountersInstrumentation(this MeterProviderBuilder builder, IConfigurationSection)
...add...
public static MeterProviderBuilder AddEventCountersInstrumentation(
this MeterProviderBuilder builder,
string name,
Action<EventCountersInstrumentationOptions> configure)
The way the pattern is implemented, if users want to bind to IConfiguration they can do something like this...
services.Configure<EventCountersInstrumentationOptions>(config.GetSection("otel:eventcounters"));
services.Configure<EventCountersInstrumentationOptions>("NamedExporter", config.GetSection("otel:eventcounters"));