Skip to content
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

OTLP Exporter: Support IDeferredMeterProviderBuilder in AddOtlpExporter #2413

Merged
merged 3 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* `MeterProviderBuilder` extension methods now support `OtlpExporterOptions`
bound to `IConfiguration` when using OpenTelemetry.Extensions.Hosting
([#2413](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2413))

## 1.2.0-alpha4

Released 2021-Sep-23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace OpenTelemetry.Metrics
public static class OtlpMetricExporterExtensions
{
/// <summary>
/// Adds OpenTelemetry Protocol (OTLP) exporter to the MeterProvider.
/// Adds <see cref="OtlpMetricsExporter"/> to the <see cref="MeterProviderBuilder"/>.
/// </summary>
/// <param name="builder"><see cref="MeterProviderBuilder"/> builder to use.</param>
/// <param name="configure">Exporter configuration options.</param>
Expand All @@ -37,7 +37,19 @@ public static MeterProviderBuilder AddOtlpExporter(this MeterProviderBuilder bui
throw new ArgumentNullException(nameof(builder));
}

var options = new OtlpExporterOptions();
if (builder is IDeferredMeterProviderBuilder deferredMeterProviderBuilder)
{
return deferredMeterProviderBuilder.Configure((sp, builder) =>
{
AddOtlpExporter(builder, sp.GetOptions<OtlpExporterOptions>(), configure);
});
}

return AddOtlpExporter(builder, new OtlpExporterOptions(), configure);
}

private static MeterProviderBuilder AddOtlpExporter(MeterProviderBuilder builder, OtlpExporterOptions options, Action<OtlpExporterOptions> configure = null)
{
configure?.Invoke(options);

var metricExporter = new OtlpMetricsExporter(options);
Expand Down