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

[feature request] Make IMeterProviderBuilder Public

Open mobratil opened this issue 5 months ago • 0 comments

Package

OpenTelemetry.Api.ProviderBuilderExtensions

Is your feature request related to a problem?

There are scenarios in which creating custom builders - often by wrapping or subclassing MeterProviderBuilder - is necessary to inject additional behavior or integrate with alternate DI helpers.
The SDK’s ConfigureServices extension method:

public static MeterProviderBuilder ConfigureServices(
    this MeterProviderBuilder meterProviderBuilder,
    Action<IServiceCollection> configure)
{
    if (meterProviderBuilder is IMeterProviderBuilder iMeterProviderBuilder)
    {
        iMeterProviderBuilder.ConfigureServices(configure);
    }

    return meterProviderBuilder;
}

executes its delegate only when the builder implements the internal IMeterProviderBuilder interface. Because IMeterProviderBuilder is internal, third‑party builders cannot implement it. As a result, the callback silently does nothing and custom builders lose access to the normal DI configuration flow.

What is the expected behavior?

Make IMeterProviderBuilder a public, stable interface.
Custom builders could then implement this interface and be fully recognized by existing extension methods, allowing them to participate in ConfigureServices extension method.

Which alternative solutions or features have you considered?

Re‑implement all extensions from MeterProviderBuilderExtensions. We copied the SDK’s helpers into our own code so they would work with a custom builder. This approach helps only for those specific methods. Many other extension methods - both in the OpenTelemetry SDK and in third‑party libraries - still check for IMeterProviderBuilder and remain unreachable. Maintaining a parallel set of helpers is brittle and quickly falls out of sync with the SDK. In short, it is not a sustainable solution.

Additional context

  • The codebase contains a comment on IMeterProviderBuilder stating it “may be made public if there is a need for it.”
  • Exposing this interface is a small, non‑breaking change that unlocks richer third‑party builder scenarios without affecting existing users.

mobratil avatar Jul 17 '25 17:07 mobratil