opentelemetry-dotnet-contrib icon indicating copy to clipboard operation
opentelemetry-dotnet-contrib copied to clipboard

DI support for configuring EventCounters

Open dpk83 opened this issue 3 years ago • 1 comments

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?

  • AddEventCountersInstrumentation work with IDeferredMeterProviderBuilder
  • 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.

dpk83 avatar Dec 15 '22 20:12 dpk83

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"));

CodeBlanch avatar Jan 10 '23 19:01 CodeBlanch