From 80ebdf083367c5996eeac0cb8f489bf5c29a2303 Mon Sep 17 00:00:00 2001
From: Alan West <3676547+alanwest@users.noreply.github.com>
Date: Tue, 22 Feb 2022 17:00:29 -0800
Subject: [PATCH 1/4] Add support for MetricReaderOptions to
AddInMemoryExporter helper methods
---
.../InMemoryExporterMetricsExtensions.cs | 62 ++++++++++++++++++-
.../OpenTelemetry.Exporter.InMemory.csproj | 1 +
2 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/src/OpenTelemetry.Exporter.InMemory/InMemoryExporterMetricsExtensions.cs b/src/OpenTelemetry.Exporter.InMemory/InMemoryExporterMetricsExtensions.cs
index a7465262adc..b43d602df8d 100644
--- a/src/OpenTelemetry.Exporter.InMemory/InMemoryExporterMetricsExtensions.cs
+++ b/src/OpenTelemetry.Exporter.InMemory/InMemoryExporterMetricsExtensions.cs
@@ -14,16 +14,20 @@
// limitations under the License.
//
+using System;
using System.Collections.Generic;
using OpenTelemetry.Exporter;
using OpenTelemetry.Internal;
namespace OpenTelemetry.Metrics
{
+ ///
+ /// Extension methods to simplify registering of the InMemory exporter.
+ ///
public static class InMemoryExporterMetricsExtensions
{
///
- /// Adds InMemory exporter to the TracerProvider.
+ /// Adds InMemory metric exporter to the using default options.
///
/// builder to use.
/// Collection which will be populated with the exported MetricItem.
@@ -33,7 +37,61 @@ public static MeterProviderBuilder AddInMemoryExporter(this MeterProviderBuilder
Guard.ThrowIfNull(builder);
Guard.ThrowIfNull(exportedItems);
- return builder.AddReader(new BaseExportingMetricReader(new InMemoryExporter(exportedItems)));
+ if (builder is IDeferredMeterProviderBuilder deferredMeterProviderBuilder)
+ {
+ return deferredMeterProviderBuilder.Configure((sp, builder) =>
+ {
+ AddInMemoryExporter(builder, exportedItems, sp.GetOptions(), null);
+ });
+ }
+
+ return AddInMemoryExporter(builder, exportedItems, new MetricReaderOptions(), null);
+ }
+
+ ///
+ /// Adds InMemory metric exporter to the using default options.
+ ///
+ /// builder to use.
+ /// Collection which will be populated with the exported MetricItem.
+ /// configuration options.
+ /// The instance of to chain the calls.
+ public static MeterProviderBuilder AddInMemoryExporter(this MeterProviderBuilder builder, ICollection exportedItems, Action configureMetricReader)
+ {
+ Guard.ThrowIfNull(builder);
+ Guard.ThrowIfNull(exportedItems);
+
+ if (builder is IDeferredMeterProviderBuilder deferredMeterProviderBuilder)
+ {
+ return deferredMeterProviderBuilder.Configure((sp, builder) =>
+ {
+ AddInMemoryExporter(builder, exportedItems, sp.GetOptions(), configureMetricReader);
+ });
+ }
+
+ return AddInMemoryExporter(builder, exportedItems, new MetricReaderOptions(), configureMetricReader);
+ }
+
+ private static MeterProviderBuilder AddInMemoryExporter(
+ MeterProviderBuilder builder,
+ ICollection exportedItems,
+ MetricReaderOptions metricReaderOptions,
+ Action configureMetricReader)
+ {
+ configureMetricReader?.Invoke(metricReaderOptions);
+
+ var metricExporter = new InMemoryExporter(exportedItems);
+
+ if (metricReaderOptions.MetricReaderType == (MetricReaderType)(-1))
+ {
+ metricReaderOptions.MetricReaderType = MetricReaderType.Manual;
+ }
+
+ var metricReader = metricReaderOptions.MetricReaderType == MetricReaderType.Manual
+ ? new BaseExportingMetricReader(metricExporter)
+ : new PeriodicExportingMetricReader(metricExporter, metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds);
+
+ metricReader.Temporality = metricReaderOptions.Temporality;
+ return builder.AddReader(metricReader);
}
}
}
diff --git a/src/OpenTelemetry.Exporter.InMemory/OpenTelemetry.Exporter.InMemory.csproj b/src/OpenTelemetry.Exporter.InMemory/OpenTelemetry.Exporter.InMemory.csproj
index 404dc1b16d2..a3c1e2b7fee 100644
--- a/src/OpenTelemetry.Exporter.InMemory/OpenTelemetry.Exporter.InMemory.csproj
+++ b/src/OpenTelemetry.Exporter.InMemory/OpenTelemetry.Exporter.InMemory.csproj
@@ -16,6 +16,7 @@
+
From 3e6fce93eced00ab3b739c62e614d367cc2b977e Mon Sep 17 00:00:00 2001
From: Alan West <3676547+alanwest@users.noreply.github.com>
Date: Tue, 22 Feb 2022 17:01:23 -0800
Subject: [PATCH 2/4] Update tests to use new AddInMemoryExporter method
---
.../Benchmarks/Metrics/HistogramBenchmarks.cs | 8 ++--
test/Benchmarks/Metrics/MetricsBenchmarks.cs | 11 ++---
.../Metrics/MetricsViewBenchmarks.cs | 6 +--
.../OtlpMetricsExporterTests.cs | 17 ++++---
.../MetricTests.cs | 8 +---
.../HttpClientTests.netcore31.cs | 12 ++---
.../Metrics/InMemoryExporterTests.cs | 5 +--
.../Metrics/MemoryEfficiencyTests.cs | 10 ++---
.../Metrics/MetricAPITest.cs | 45 +++++++++----------
.../Metrics/MultipleReadersTests.cs | 22 ++++-----
10 files changed, 63 insertions(+), 81 deletions(-)
diff --git a/test/Benchmarks/Metrics/HistogramBenchmarks.cs b/test/Benchmarks/Metrics/HistogramBenchmarks.cs
index aff46b76686..d2af7462266 100644
--- a/test/Benchmarks/Metrics/HistogramBenchmarks.cs
+++ b/test/Benchmarks/Metrics/HistogramBenchmarks.cs
@@ -20,7 +20,6 @@
using System.Threading;
using BenchmarkDotNet.Attributes;
using OpenTelemetry;
-using OpenTelemetry.Exporter;
using OpenTelemetry.Metrics;
using OpenTelemetry.Tests;
@@ -76,11 +75,14 @@ public void Setup()
}
var exportedItems = new List();
- var reader = new PeriodicExportingMetricReader(new InMemoryExporter(exportedItems), 1000);
this.provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(this.meter.Name)
- .AddReader(reader)
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
+ {
+ metricReaderOptions.MetricReaderType = MetricReaderType.Periodic;
+ metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 1000;
+ })
.AddView(this.histogramLong.Name, new ExplicitBucketHistogramConfiguration() { Boundaries = this.bounds })
.AddView(this.histogramDouble.Name, new ExplicitBucketHistogramConfiguration() { Boundaries = this.bounds })
.Build();
diff --git a/test/Benchmarks/Metrics/MetricsBenchmarks.cs b/test/Benchmarks/Metrics/MetricsBenchmarks.cs
index 0fbef5a11b7..44266e6b6a1 100644
--- a/test/Benchmarks/Metrics/MetricsBenchmarks.cs
+++ b/test/Benchmarks/Metrics/MetricsBenchmarks.cs
@@ -71,13 +71,14 @@ public void Setup()
this.meter = new Meter(Utils.GetCurrentMethodName());
var exportedItems = new List();
- var reader = new PeriodicExportingMetricReader(new InMemoryExporter(exportedItems), 1000)
- {
- Temporality = this.AggregationTemporality,
- };
this.provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(this.meter.Name) // All instruments from this meter are enabled.
- .AddReader(reader)
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
+ {
+ metricReaderOptions.MetricReaderType = MetricReaderType.Periodic;
+ metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 1000;
+ metricReaderOptions.Temporality = this.AggregationTemporality;
+ })
.Build();
this.counter = this.meter.CreateCounter("counter");
diff --git a/test/Benchmarks/Metrics/MetricsViewBenchmarks.cs b/test/Benchmarks/Metrics/MetricsViewBenchmarks.cs
index 0bf3d40d506..e93f3cb9aa6 100644
--- a/test/Benchmarks/Metrics/MetricsViewBenchmarks.cs
+++ b/test/Benchmarks/Metrics/MetricsViewBenchmarks.cs
@@ -89,7 +89,7 @@ public void Setup()
{
this.provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(this.meter.Name)
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(this.metrics)))
+ .AddInMemoryExporter(this.metrics)
.Build();
}
else if (this.ViewConfig == ViewConfiguration.ViewNoInstrSelect)
@@ -97,7 +97,7 @@ public void Setup()
this.provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(this.meter.Name)
.AddView("nomatch", new MetricStreamConfiguration() { TagKeys = new string[] { "DimName1", "DimName2", "DimName3" } })
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(this.metrics)))
+ .AddInMemoryExporter(this.metrics)
.Build();
}
else if (this.ViewConfig == ViewConfiguration.ViewSelectsInstr)
@@ -105,7 +105,7 @@ public void Setup()
this.provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(this.meter.Name)
.AddView(this.counter.Name, new MetricStreamConfiguration() { TagKeys = new string[] { "DimName1", "DimName2", "DimName3" } })
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(this.metrics)))
+ .AddInMemoryExporter(this.metrics)
.Build();
}
}
diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs
index 75b170bf501..e64595179b0 100644
--- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs
+++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs
@@ -240,11 +240,10 @@ public void TestCounterToOltpMetric(string name, string description, string unit
using var meter = new Meter(Utils.GetCurrentMethodName());
using var provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(
- new BaseExportingMetricReader(new InMemoryExporter(metrics))
- {
- Temporality = aggregationTemporality,
- })
+ .AddInMemoryExporter(metrics, metricReaderOptions =>
+ {
+ metricReaderOptions.Temporality = aggregationTemporality;
+ })
.Build();
var attributes = ToAttributes(keysValues).ToArray();
@@ -334,13 +333,13 @@ public void TestHistogramToOltpMetric(string name, string description, string un
{
var metrics = new List();
- var metricReader = new BaseExportingMetricReader(new InMemoryExporter(metrics));
- metricReader.Temporality = aggregationTemporality;
-
using var meter = new Meter(Utils.GetCurrentMethodName());
using var provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(metricReader)
+ .AddInMemoryExporter(metrics, metricReaderOptions =>
+ {
+ metricReaderOptions.Temporality = aggregationTemporality;
+ })
.Build();
var attributes = ToAttributes(keysValues).ToArray();
diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs
index bfeda28b387..b5d8a6d5905 100644
--- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs
+++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs
@@ -19,7 +19,6 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Testing;
-using OpenTelemetry.Exporter;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
#if NETCOREAPP3_1
@@ -57,15 +56,10 @@ public void AddAspNetCoreInstrumentation_BadArgs()
public async Task RequestMetricIsCaptured()
{
var metricItems = new List();
- var metricExporter = new InMemoryExporter(metricItems);
- var metricReader = new BaseExportingMetricReader(metricExporter)
- {
- Temporality = AggregationTemporality.Cumulative,
- };
this.meterProvider = Sdk.CreateMeterProviderBuilder()
.AddAspNetCoreInstrumentation()
- .AddReader(metricReader)
+ .AddInMemoryExporter(metricItems)
.Build();
using (var client = this.factory.CreateClient())
diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs
index 9620e10335a..b702fc3e349 100644
--- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs
+++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs
@@ -25,7 +25,6 @@
using System.Threading.Tasks;
using Moq;
using Newtonsoft.Json;
-using OpenTelemetry.Exporter;
using OpenTelemetry.Metrics;
using OpenTelemetry.Tests;
using OpenTelemetry.Trace;
@@ -55,16 +54,11 @@ public async Task HttpOutCallsAreCollectedSuccessfullyAsync(HttpTestData.HttpOut
var processor = new Mock>();
tc.Url = HttpTestData.NormalizeValues(tc.Url, host, port);
- var metricItems = new List();
- var metricExporter = new InMemoryExporter(metricItems);
+ var metrics = new List();
- var metricReader = new BaseExportingMetricReader(metricExporter)
- {
- Temporality = AggregationTemporality.Cumulative,
- };
var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddHttpClientInstrumentation()
- .AddReader(metricReader)
+ .AddInMemoryExporter(metrics)
.Build();
using (serverLifeTime)
@@ -107,7 +101,7 @@ public async Task HttpOutCallsAreCollectedSuccessfullyAsync(HttpTestData.HttpOut
meterProvider.Dispose();
- var requestMetrics = metricItems
+ var requestMetrics = metrics
.Where(metric => metric.Name == "http.client.duration")
.ToArray();
diff --git a/test/OpenTelemetry.Tests/Metrics/InMemoryExporterTests.cs b/test/OpenTelemetry.Tests/Metrics/InMemoryExporterTests.cs
index 5f5914be28e..0573ad703f6 100644
--- a/test/OpenTelemetry.Tests/Metrics/InMemoryExporterTests.cs
+++ b/test/OpenTelemetry.Tests/Metrics/InMemoryExporterTests.cs
@@ -16,7 +16,6 @@
using System.Collections.Generic;
using System.Diagnostics.Metrics;
-using OpenTelemetry.Exporter;
using OpenTelemetry.Tests;
using Xunit;
@@ -32,9 +31,9 @@ public void InMemoryExporterShouldDeepCopyMetricPoints()
using var meter = new Meter(Utils.GetCurrentMethodName());
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(exportedItems))
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- Temporality = AggregationTemporality.Delta,
+ metricReaderOptions.Temporality = AggregationTemporality.Delta;
})
.Build();
diff --git a/test/OpenTelemetry.Tests/Metrics/MemoryEfficiencyTests.cs b/test/OpenTelemetry.Tests/Metrics/MemoryEfficiencyTests.cs
index c241519b95e..646cc634249 100644
--- a/test/OpenTelemetry.Tests/Metrics/MemoryEfficiencyTests.cs
+++ b/test/OpenTelemetry.Tests/Metrics/MemoryEfficiencyTests.cs
@@ -16,7 +16,6 @@
using System.Collections.Generic;
using System.Diagnostics.Metrics;
-using OpenTelemetry.Exporter;
using OpenTelemetry.Tests;
using Xunit;
@@ -35,11 +34,10 @@ public void ExportOnlyWhenPointChanged(AggregationTemporality temporality)
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(
- new BaseExportingMetricReader(new InMemoryExporter(exportedItems))
- {
- Temporality = temporality,
- })
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
+ {
+ metricReaderOptions.Temporality = temporality;
+ })
.Build();
var counter = meter.CreateCounter("meter");
diff --git a/test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs b/test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs
index cb5d1447fef..9e29ad9b0d1 100644
--- a/test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs
+++ b/test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs
@@ -157,9 +157,9 @@ public void DuplicateInstrumentNamesFromSameMeterAreNotAllowed(AggregationTempor
using var meter = new Meter($"{Utils.GetCurrentMethodName()}.{temporality}");
var meterProviderBuilder = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(exportedItems))
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- Temporality = temporality,
+ metricReaderOptions.Temporality = temporality;
});
if (hasView)
@@ -207,9 +207,9 @@ public void DuplicateInstrumentNamesFromDifferentMetersAreAllowed(AggregationTem
var meterProviderBuilder = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter1.Name)
.AddMeter(meter2.Name)
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(exportedItems))
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- Temporality = temporality,
+ metricReaderOptions.Temporality = temporality;
});
if (hasView)
@@ -326,9 +326,9 @@ public void CounterAggregationTest(bool exportDelta)
var counterLong = meter.CreateCounter("mycounter");
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(exportedItems))
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative,
+ metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
})
.Build();
@@ -400,9 +400,9 @@ public void ObservableCounterAggregationTest(bool exportDelta)
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(exportedItems))
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative,
+ metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
})
.Build();
@@ -468,9 +468,9 @@ public void ObservableCounterWithTagsAggregationTest(bool exportDelta)
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(exportedItems))
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative,
+ metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
})
.Build();
@@ -559,9 +559,9 @@ public void ObservableCounterSpatialAggregationTest(bool exportDelta)
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(exportedItems))
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative,
+ metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
})
.AddView("requestCount", new MetricStreamConfiguration() { TagKeys = new string[] { } })
.Build();
@@ -598,9 +598,9 @@ public void DimensionsAreOrderInsensitiveWithSortedKeysFirst(bool exportDelta)
var counterLong = meter.CreateCounter("Counter");
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(exportedItems))
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative,
+ metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
})
.Build();
@@ -689,9 +689,9 @@ public void DimensionsAreOrderInsensitiveWithUnsortedKeysFirst(bool exportDelta)
var counterLong = meter.CreateCounter("Counter");
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(exportedItems))
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative,
+ metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
})
.Build();
@@ -783,9 +783,9 @@ public void TestInstrumentDisposal(AggregationTemporality temporality)
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter1.Name)
.AddMeter(meter2.Name)
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(exportedItems))
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- Temporality = temporality,
+ metricReaderOptions.Temporality = temporality;
})
.Build();
@@ -850,9 +850,9 @@ int MetricPointCount()
var counterLong = meter.CreateCounter("mycounterCapTest");
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(new BaseExportingMetricReader(new InMemoryExporter(exportedItems))
+ .AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- Temporality = temporality,
+ metricReaderOptions.Temporality = temporality;
})
.Build();
@@ -1152,12 +1152,11 @@ private void MultithreadedCounterTest(T deltaValueUpdatedByEachCall)
where T : struct, IComparable
{
var metricItems = new List();
- var metricReader = new BaseExportingMetricReader(new InMemoryExporter(metricItems));
using var meter = new Meter($"{Utils.GetCurrentMethodName()}.{typeof(T).Name}.{deltaValueUpdatedByEachCall}");
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(metricReader)
+ .AddInMemoryExporter(metricItems)
.Build();
var argToThread = new UpdateThreadArguments
@@ -1186,7 +1185,7 @@ private void MultithreadedCounterTest(T deltaValueUpdatedByEachCall)
this.output.WriteLine($"Took {sw.ElapsedMilliseconds} msecs. Total threads: {numberOfThreads}, each thread doing {numberOfMetricUpdateByEachThread} recordings.");
- metricReader.Collect();
+ meterProvider.ForceFlush();
if (typeof(T) == typeof(long))
{
diff --git a/test/OpenTelemetry.Tests/Metrics/MultipleReadersTests.cs b/test/OpenTelemetry.Tests/Metrics/MultipleReadersTests.cs
index ba08b0644a5..ff4fcf652cb 100644
--- a/test/OpenTelemetry.Tests/Metrics/MultipleReadersTests.cs
+++ b/test/OpenTelemetry.Tests/Metrics/MultipleReadersTests.cs
@@ -32,18 +32,8 @@ public class MultipleReadersTests
public void SdkSupportsMultipleReaders(AggregationTemporality aggregationTemporality, bool hasViews)
{
var exportedItems1 = new List();
- using var deltaExporter1 = new InMemoryExporter(exportedItems1);
- using var deltaReader1 = new BaseExportingMetricReader(deltaExporter1)
- {
- Temporality = AggregationTemporality.Delta,
- };
-
var exportedItems2 = new List();
- using var deltaExporter2 = new InMemoryExporter(exportedItems2);
- using var deltaReader2 = new BaseExportingMetricReader(deltaExporter2)
- {
- Temporality = aggregationTemporality,
- };
+
using var meter = new Meter($"{Utils.GetCurrentMethodName()}.{aggregationTemporality}.{hasViews}");
var counter = meter.CreateCounter("counter");
@@ -55,8 +45,14 @@ public void SdkSupportsMultipleReaders(AggregationTemporality aggregationTempora
var meterProviderBuilder = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
- .AddReader(deltaReader1)
- .AddReader(deltaReader2);
+ .AddInMemoryExporter(exportedItems1, metricReaderOptions =>
+ {
+ metricReaderOptions.Temporality = AggregationTemporality.Delta;
+ })
+ .AddInMemoryExporter(exportedItems2, metricReaderOptions =>
+ {
+ metricReaderOptions.Temporality = aggregationTemporality;
+ });
if (hasViews)
{
From b1d939287dd5514e15eb78181b89ed4caea62cbd Mon Sep 17 00:00:00 2001
From: Alan West <3676547+alanwest@users.noreply.github.com>
Date: Tue, 22 Feb 2022 17:15:18 -0800
Subject: [PATCH 3/4] Update public API
---
.../.publicApi/net461/PublicAPI.Unshipped.txt | 3 ++-
.../.publicApi/netstandard2.0/PublicAPI.Unshipped.txt | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/OpenTelemetry.Exporter.InMemory/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.InMemory/.publicApi/net461/PublicAPI.Unshipped.txt
index 8e3bd117f68..ca21920895c 100644
--- a/src/OpenTelemetry.Exporter.InMemory/.publicApi/net461/PublicAPI.Unshipped.txt
+++ b/src/OpenTelemetry.Exporter.InMemory/.publicApi/net461/PublicAPI.Unshipped.txt
@@ -1,2 +1,3 @@
OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions
-static OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions.AddInMemoryExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Collections.Generic.ICollection exportedItems) -> OpenTelemetry.Metrics.MeterProviderBuilder
\ No newline at end of file
+static OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions.AddInMemoryExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Collections.Generic.ICollection exportedItems) -> OpenTelemetry.Metrics.MeterProviderBuilder
+static OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions.AddInMemoryExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Collections.Generic.ICollection exportedItems, System.Action configureMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder
\ No newline at end of file
diff --git a/src/OpenTelemetry.Exporter.InMemory/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.InMemory/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt
index 8e3bd117f68..ca21920895c 100644
--- a/src/OpenTelemetry.Exporter.InMemory/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt
+++ b/src/OpenTelemetry.Exporter.InMemory/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt
@@ -1,2 +1,3 @@
OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions
-static OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions.AddInMemoryExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Collections.Generic.ICollection exportedItems) -> OpenTelemetry.Metrics.MeterProviderBuilder
\ No newline at end of file
+static OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions.AddInMemoryExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Collections.Generic.ICollection exportedItems) -> OpenTelemetry.Metrics.MeterProviderBuilder
+static OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions.AddInMemoryExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Collections.Generic.ICollection exportedItems, System.Action configureMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder
\ No newline at end of file
From ff401a192752b8579982027bbf171bc4186561fa Mon Sep 17 00:00:00 2001
From: Alan West <3676547+alanwest@users.noreply.github.com>
Date: Tue, 22 Feb 2022 17:41:04 -0800
Subject: [PATCH 4/4] Update changelog
---
src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md b/src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md
index db37a70a6c4..18449e8d085 100644
--- a/src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md
+++ b/src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md
@@ -2,6 +2,10 @@
## Unreleased
+* Adds the ability to configure `MetricReaderOptions` via the
+ `AddInMemoryExporter` extension method.
+ ([#2931](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2931))
+
## 1.2.0-rc2
Released 2022-Feb-02