Skip to content

Commit

Permalink
Test when periodic metric reader options is null
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwest committed Apr 15, 2022
1 parent 2bd97bf commit 162650b
Showing 1 changed file with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,39 @@ public void TestAddOtlpExporter_SetsCorrectMetricReaderDefaults()
.AddOtlpExporter()
.Build();

var bindingFlags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
CheckMetricReaderDefaults();

var metricReader = typeof(MetricReader)
.Assembly
.GetType("OpenTelemetry.Metrics.MeterProviderSdk")
.GetField("reader", bindingFlags)
.GetValue(meterProvider) as PeriodicExportingMetricReader;
meterProvider.Dispose();

Assert.NotNull(metricReader);
meterProvider = Sdk.CreateMeterProviderBuilder()
.AddOtlpExporter((exporterOptions, metricReaderOptions) =>
{
metricReaderOptions.PeriodicExportingMetricReaderOptions = null;
})
.Build();

CheckMetricReaderDefaults();

meterProvider.Dispose();

var exportIntervalMilliseconds = (int)typeof(PeriodicExportingMetricReader)
.GetField("ExportIntervalMilliseconds", bindingFlags)
.GetValue(metricReader);
void CheckMetricReaderDefaults()
{
var bindingFlags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;

var metricReader = typeof(MetricReader)
.Assembly
.GetType("OpenTelemetry.Metrics.MeterProviderSdk")
.GetField("reader", bindingFlags)
.GetValue(meterProvider) as PeriodicExportingMetricReader;

Assert.NotNull(metricReader);

Assert.Equal(60000, exportIntervalMilliseconds);
var exportIntervalMilliseconds = (int)typeof(PeriodicExportingMetricReader)
.GetField("ExportIntervalMilliseconds", bindingFlags)
.GetValue(metricReader);

Assert.Equal(60000, exportIntervalMilliseconds);
}
}

[Fact]
Expand Down

0 comments on commit 162650b

Please sign in to comment.