Skip to content

Commit

Permalink
Support IDeferredMeterProviderBuilder in OTLP exporter.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch committed Sep 27, 2021
1 parent 38ee521 commit bd93999
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
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
([#TBD](https://github.com/open-telemetry/opentelemetry-dotnet/pull/TBD))

## 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

0 comments on commit bd93999

Please sign in to comment.