diff --git a/examples/Console/TestMetrics.cs b/examples/Console/TestMetrics.cs
index b9864e81733..35fc3dd1324 100644
--- a/examples/Console/TestMetrics.cs
+++ b/examples/Console/TestMetrics.cs
@@ -71,7 +71,7 @@ internal static object Run(MetricsOptions options)
exporterOptions.Protocol = options.UseGrpc ? OtlpExportProtocol.Grpc : OtlpExportProtocol.HttpProtobuf;
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds;
- metricReaderOptions.Temporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
+ metricReaderOptions.TemporalityPreference = options.IsDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
});
}
else
@@ -82,7 +82,7 @@ internal static object Run(MetricsOptions options)
exporterOptions.Targets = ConsoleExporterOutputTargets.Console;
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds;
- metricReaderOptions.Temporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
+ metricReaderOptions.TemporalityPreference = options.IsDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
});
}
diff --git a/src/OpenTelemetry.Exporter.Prometheus/PrometheusExporter.cs b/src/OpenTelemetry.Exporter.Prometheus/PrometheusExporter.cs
index e49c5d16831..4af4eb17fc9 100644
--- a/src/OpenTelemetry.Exporter.Prometheus/PrometheusExporter.cs
+++ b/src/OpenTelemetry.Exporter.Prometheus/PrometheusExporter.cs
@@ -23,7 +23,6 @@ namespace OpenTelemetry.Exporter
///
/// Exporter of OpenTelemetry metrics to Prometheus.
///
- [AggregationTemporality(AggregationTemporality.Cumulative)]
[ExportModes(ExportModes.Pull)]
public class PrometheusExporter : BaseExporter, IPullMetricExporter
{
diff --git a/src/OpenTelemetry.Exporter.Prometheus/PrometheusExporterMeterProviderBuilderExtensions.cs b/src/OpenTelemetry.Exporter.Prometheus/PrometheusExporterMeterProviderBuilderExtensions.cs
index 6d42926589a..ada7d1c90d1 100644
--- a/src/OpenTelemetry.Exporter.Prometheus/PrometheusExporterMeterProviderBuilderExtensions.cs
+++ b/src/OpenTelemetry.Exporter.Prometheus/PrometheusExporterMeterProviderBuilderExtensions.cs
@@ -49,6 +49,7 @@ private static MeterProviderBuilder AddPrometheusExporter(MeterProviderBuilder b
var exporter = new PrometheusExporter(options);
var reader = new BaseExportingMetricReader(exporter);
+ reader.TemporalityPreference = MetricReaderTemporalityPreference.Cumulative;
return builder.AddReader(reader);
}
diff --git a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt
index 9f27c359012..d980f563a39 100644
--- a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt
+++ b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt
@@ -5,17 +5,14 @@ OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.get -> double[]
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.set -> void
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.ExplicitBucketHistogramConfiguration() -> void
+OpenTelemetry.Metrics.MetricReader.TemporalityPreference.get -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
+OpenTelemetry.Metrics.MetricReader.TemporalityPreference.set -> void
OpenTelemetry.Metrics.MetricReaderOptions
OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderOptions() -> void
OpenTelemetry.Metrics.MetricReaderOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions
-OpenTelemetry.Metrics.MetricReaderOptions.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
-OpenTelemetry.Metrics.MetricReaderOptions.Temporality.set -> void
OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.AggregationTemporality.Cumulative = 1 -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.AggregationTemporality.Delta = 2 -> OpenTelemetry.Metrics.AggregationTemporality
-OpenTelemetry.Metrics.AggregationTemporalityAttribute
-OpenTelemetry.Metrics.AggregationTemporalityAttribute.AggregationTemporalityAttribute(OpenTelemetry.Metrics.AggregationTemporality temporality) -> void
-OpenTelemetry.Metrics.AggregationTemporalityAttribute.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.BaseExportingMetricReader
OpenTelemetry.Metrics.BaseExportingMetricReader.BaseExportingMetricReader(OpenTelemetry.BaseExporter exporter) -> void
OpenTelemetry.Metrics.BaseExportingMetricReader.SupportedExportModes.get -> OpenTelemetry.Metrics.ExportModes
@@ -76,8 +73,11 @@ OpenTelemetry.Metrics.MetricReader.Collect(int timeoutMilliseconds = -1) -> bool
OpenTelemetry.Metrics.MetricReader.Dispose() -> void
OpenTelemetry.Metrics.MetricReader.MetricReader() -> void
OpenTelemetry.Metrics.MetricReader.Shutdown(int timeoutMilliseconds = -1) -> bool
-OpenTelemetry.Metrics.MetricReader.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
-OpenTelemetry.Metrics.MetricReader.Temporality.set -> void
+OpenTelemetry.Metrics.MetricReaderOptions.TemporalityPreference.get -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
+OpenTelemetry.Metrics.MetricReaderOptions.TemporalityPreference.set -> void
+OpenTelemetry.Metrics.MetricReaderTemporalityPreference
+OpenTelemetry.Metrics.MetricReaderTemporalityPreference.Cumulative = 1 -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
+OpenTelemetry.Metrics.MetricReaderTemporalityPreference.Delta = 2 -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
OpenTelemetry.Metrics.MetricStreamConfiguration
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.get -> string
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.set -> void
diff --git a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt
index 9f27c359012..d980f563a39 100644
--- a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt
+++ b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt
@@ -5,17 +5,14 @@ OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.get -> double[]
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.set -> void
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.ExplicitBucketHistogramConfiguration() -> void
+OpenTelemetry.Metrics.MetricReader.TemporalityPreference.get -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
+OpenTelemetry.Metrics.MetricReader.TemporalityPreference.set -> void
OpenTelemetry.Metrics.MetricReaderOptions
OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderOptions() -> void
OpenTelemetry.Metrics.MetricReaderOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions
-OpenTelemetry.Metrics.MetricReaderOptions.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
-OpenTelemetry.Metrics.MetricReaderOptions.Temporality.set -> void
OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.AggregationTemporality.Cumulative = 1 -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.AggregationTemporality.Delta = 2 -> OpenTelemetry.Metrics.AggregationTemporality
-OpenTelemetry.Metrics.AggregationTemporalityAttribute
-OpenTelemetry.Metrics.AggregationTemporalityAttribute.AggregationTemporalityAttribute(OpenTelemetry.Metrics.AggregationTemporality temporality) -> void
-OpenTelemetry.Metrics.AggregationTemporalityAttribute.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.BaseExportingMetricReader
OpenTelemetry.Metrics.BaseExportingMetricReader.BaseExportingMetricReader(OpenTelemetry.BaseExporter exporter) -> void
OpenTelemetry.Metrics.BaseExportingMetricReader.SupportedExportModes.get -> OpenTelemetry.Metrics.ExportModes
@@ -76,8 +73,11 @@ OpenTelemetry.Metrics.MetricReader.Collect(int timeoutMilliseconds = -1) -> bool
OpenTelemetry.Metrics.MetricReader.Dispose() -> void
OpenTelemetry.Metrics.MetricReader.MetricReader() -> void
OpenTelemetry.Metrics.MetricReader.Shutdown(int timeoutMilliseconds = -1) -> bool
-OpenTelemetry.Metrics.MetricReader.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
-OpenTelemetry.Metrics.MetricReader.Temporality.set -> void
+OpenTelemetry.Metrics.MetricReaderOptions.TemporalityPreference.get -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
+OpenTelemetry.Metrics.MetricReaderOptions.TemporalityPreference.set -> void
+OpenTelemetry.Metrics.MetricReaderTemporalityPreference
+OpenTelemetry.Metrics.MetricReaderTemporalityPreference.Cumulative = 1 -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
+OpenTelemetry.Metrics.MetricReaderTemporalityPreference.Delta = 2 -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
OpenTelemetry.Metrics.MetricStreamConfiguration
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.get -> string
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.set -> void
diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md
index 284489a196a..e6d9adffefe 100644
--- a/src/OpenTelemetry/CHANGELOG.md
+++ b/src/OpenTelemetry/CHANGELOG.md
@@ -2,6 +2,19 @@
## Unreleased
+* Removed the `Temporality` setting on `MetricReader` and replaced it with
+ `TemporalityPreference`. This is a breaking change.
+ `TemporalityPreference` is used to determine the `AggregationTemporality`
+ used on a per-instrument kind basis. Currently, there are two preferences:
+ * `Cumulative`: Measurements from all instrument kinds are aggregated using
+ `AggregationTemporality.Cumulative`.
+ * `Delta`: Measurements from `Counter`, `ObservableCounter`, and `Histogram`
+ instruments are aggregated using `AggregationTemporality.Delta`. When
+ UpDownCounters are supported with
+ [DiagnosticSource version 7.0 onwards](https://www.nuget.org/packages/System.Diagnostics.DiagnosticSource/7.0.0-preview.2.22152.2),
+ they will be aggregated using `AggregationTemporality.Cumulative`.
+ ([#3153](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3153))
+
* Fix issue where `ExplicitBucketHistogramConfiguration` could be used to
configure metric streams for instruments that are not histograms. Currently,
it is not possible to change the aggregation of an instrument with views. This
diff --git a/src/OpenTelemetry/Internal/PeriodicExportingMetricReaderHelper.cs b/src/OpenTelemetry/Internal/PeriodicExportingMetricReaderHelper.cs
index 487e8aeac9d..ee6a4989bed 100644
--- a/src/OpenTelemetry/Internal/PeriodicExportingMetricReaderHelper.cs
+++ b/src/OpenTelemetry/Internal/PeriodicExportingMetricReaderHelper.cs
@@ -34,7 +34,7 @@ internal static PeriodicExportingMetricReader CreatePeriodicExportingMetricReade
var metricReader = new PeriodicExportingMetricReader(exporter, exportInterval, exportTimeout)
{
- Temporality = options.Temporality,
+ TemporalityPreference = options.TemporalityPreference,
};
return metricReader;
diff --git a/src/OpenTelemetry/Metrics/AggregationTemporalityAttribute.cs b/src/OpenTelemetry/Metrics/AggregationTemporalityAttribute.cs
deleted file mode 100644
index 3e4c7e9b266..00000000000
--- a/src/OpenTelemetry/Metrics/AggregationTemporalityAttribute.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-//
-// Copyright The OpenTelemetry Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-using System;
-
-namespace OpenTelemetry.Metrics
-{
- [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
- public sealed class AggregationTemporalityAttribute : Attribute
- {
- private readonly AggregationTemporality temporality;
-
- public AggregationTemporalityAttribute(AggregationTemporality temporality)
- {
- this.temporality = temporality;
- }
-
- public AggregationTemporality Temporality => this.temporality;
- }
-}
diff --git a/src/OpenTelemetry/Metrics/BaseExportingMetricReader.cs b/src/OpenTelemetry/Metrics/BaseExportingMetricReader.cs
index 526df4ee941..647025fd719 100644
--- a/src/OpenTelemetry/Metrics/BaseExportingMetricReader.cs
+++ b/src/OpenTelemetry/Metrics/BaseExportingMetricReader.cs
@@ -45,14 +45,7 @@ public BaseExportingMetricReader(BaseExporter exporter)
this.exporter = exporter;
var exportorType = exporter.GetType();
- var attributes = exportorType.GetCustomAttributes(typeof(AggregationTemporalityAttribute), true);
- if (attributes.Length > 0)
- {
- var attr = (AggregationTemporalityAttribute)attributes[attributes.Length - 1];
- this.Temporality = attr.Temporality;
- }
-
- attributes = exportorType.GetCustomAttributes(typeof(ExportModesAttribute), true);
+ var attributes = exportorType.GetCustomAttributes(typeof(ExportModesAttribute), true);
if (attributes.Length > 0)
{
var attr = (ExportModesAttribute)attributes[attributes.Length - 1];
diff --git a/src/OpenTelemetry/Metrics/MetricReader.cs b/src/OpenTelemetry/Metrics/MetricReader.cs
index 1cba0474796..ed3ee50d4a1 100644
--- a/src/OpenTelemetry/Metrics/MetricReader.cs
+++ b/src/OpenTelemetry/Metrics/MetricReader.cs
@@ -16,6 +16,7 @@
using System;
using System.Diagnostics;
+using System.Diagnostics.Metrics;
using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry.Internal;
@@ -27,35 +28,74 @@ namespace OpenTelemetry.Metrics
///
public abstract partial class MetricReader : IDisposable
{
- private const AggregationTemporality AggregationTemporalityUnspecified = (AggregationTemporality)0;
+ private const MetricReaderTemporalityPreference MetricReaderTemporalityPreferenceUnspecified = (MetricReaderTemporalityPreference)0;
+
+ private static Func cumulativeTemporatlityPreferenceFunc =
+ (instrumentType) => AggregationTemporality.Cumulative;
+
+ private static Func monotonicDeltaTemporatlityPreferenceFunc = (instrumentType) =>
+ {
+ return instrumentType.GetGenericTypeDefinition() switch
+ {
+ var type when type == typeof(Counter<>) => AggregationTemporality.Delta,
+ var type when type == typeof(ObservableCounter<>) => AggregationTemporality.Delta,
+ var type when type == typeof(Histogram<>) => AggregationTemporality.Delta,
+
+ // Temporatlity is not defined for gauges, so this does not really affect anything.
+ var type when type == typeof(ObservableGauge<>) => AggregationTemporality.Delta,
+
+ // With .NET 7 the OpenTelemetry .NET SDK will support UpDownCounters.
+ // These will be aggregated using Cumulative temporatlity.
+ // See:
+ // https://docs.microsoft.com/dotnet/api/system.diagnostics.metrics.updowncounter-1
+ // https://docs.microsoft.com/dotnet/api/system.diagnostics.metrics.observableupdowncounter-1
+ // var type when type == typeof(UpDownCounter<>) => AggregationTemporality.Cumulative,
+ // var type when type == typeof(ObservableUpDownCounter<>) => AggregationTemporality.Cumulative,
+
+ // TODO: Consider logging here because we should not fall through to this case.
+ _ => AggregationTemporality.Delta,
+ };
+ };
+
private readonly object newTaskLock = new();
private readonly object onCollectLock = new();
private readonly TaskCompletionSource shutdownTcs = new();
- private AggregationTemporality temporality = AggregationTemporalityUnspecified;
+ private MetricReaderTemporalityPreference temporalityPreference = MetricReaderTemporalityPreferenceUnspecified;
+ private Func temporatlityFunc = cumulativeTemporatlityPreferenceFunc;
private int shutdownCount;
private TaskCompletionSource collectionTcs;
private BaseProvider parentProvider;
- public AggregationTemporality Temporality
+ public MetricReaderTemporalityPreference TemporalityPreference
{
get
{
- if (this.temporality == AggregationTemporalityUnspecified)
+ if (this.temporalityPreference == MetricReaderTemporalityPreferenceUnspecified)
{
- this.temporality = AggregationTemporality.Cumulative;
+ this.temporalityPreference = MetricReaderTemporalityPreference.Cumulative;
}
- return this.temporality;
+ return this.temporalityPreference;
}
set
{
- if (this.temporality != AggregationTemporalityUnspecified)
+ if (this.temporalityPreference != MetricReaderTemporalityPreferenceUnspecified)
{
- throw new NotSupportedException($"The temporality cannot be modified (the current value is {this.temporality}).");
+ throw new NotSupportedException($"The temporality preference cannot be modified (the current value is {this.temporalityPreference}).");
}
- this.temporality = value;
+ this.temporalityPreference = value;
+ switch (value)
+ {
+ case MetricReaderTemporalityPreference.Delta:
+ this.temporatlityFunc = monotonicDeltaTemporatlityPreferenceFunc;
+ break;
+ case MetricReaderTemporalityPreference.Cumulative:
+ default:
+ this.temporatlityFunc = cumulativeTemporatlityPreferenceFunc;
+ break;
+ }
}
}
diff --git a/src/OpenTelemetry/Metrics/MetricReaderExt.cs b/src/OpenTelemetry/Metrics/MetricReaderExt.cs
index 83a64d4eee9..87ef37cec11 100644
--- a/src/OpenTelemetry/Metrics/MetricReaderExt.cs
+++ b/src/OpenTelemetry/Metrics/MetricReaderExt.cs
@@ -36,6 +36,11 @@ public abstract partial class MetricReader
private Metric[] metricsCurrentBatch;
private int metricIndex = -1;
+ internal AggregationTemporality GetAggregationTemporality(Type instrumentType)
+ {
+ return this.temporatlityFunc(instrumentType);
+ }
+
internal Metric AddMetricWithNoViews(Instrument instrument)
{
var metricStreamIdentity = new MetricStreamIdentity(instrument, metricStreamConfiguration: null);
@@ -66,7 +71,7 @@ internal Metric AddMetricWithNoViews(Instrument instrument)
Metric metric = null;
try
{
- metric = new Metric(metricStreamIdentity, this.Temporality, this.maxMetricPointsPerMetricStream);
+ metric = new Metric(metricStreamIdentity, this.GetAggregationTemporality(metricStreamIdentity.InstrumentType), this.maxMetricPointsPerMetricStream);
}
catch (NotSupportedException nse)
{
@@ -152,7 +157,7 @@ internal List AddMetricsListWithViews(Instrument instrument, List
- /// Gets or sets the AggregationTemporality used for Histogram
- /// and Sum metrics.
+ /// Gets or sets the .
///
- public AggregationTemporality Temporality { get; set; } = AggregationTemporality.Cumulative;
+ public MetricReaderTemporalityPreference TemporalityPreference { get; set; } = MetricReaderTemporalityPreference.Cumulative;
///
/// Gets the options.
diff --git a/src/OpenTelemetry/Metrics/MetricReaderTemporalityPreference.cs b/src/OpenTelemetry/Metrics/MetricReaderTemporalityPreference.cs
new file mode 100644
index 00000000000..ad21319910f
--- /dev/null
+++ b/src/OpenTelemetry/Metrics/MetricReaderTemporalityPreference.cs
@@ -0,0 +1,35 @@
+//
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+namespace OpenTelemetry.Metrics;
+
+///
+/// Defines the behavior of a
+/// with respect to .
+///
+public enum MetricReaderTemporalityPreference
+{
+ ///
+ /// All aggregations are performed using cumulative temporatlity.
+ ///
+ Cumulative = 1,
+
+ ///
+ /// All measurements that are monotnic in nature are aggregated using delta temporality.
+ /// Aggregations of non-monotonic measurements use cumulative temporality.
+ ///
+ Delta = 2,
+}
diff --git a/test/Benchmarks/Metrics/MetricCollectBenchmarks.cs b/test/Benchmarks/Metrics/MetricCollectBenchmarks.cs
index a7e27ea9d65..c90ca299956 100644
--- a/test/Benchmarks/Metrics/MetricCollectBenchmarks.cs
+++ b/test/Benchmarks/Metrics/MetricCollectBenchmarks.cs
@@ -88,7 +88,7 @@ void ProcessExport(Batch batch)
this.reader = new BaseExportingMetricReader(metricExporter)
{
- Temporality = AggregationTemporality.Cumulative,
+ TemporalityPreference = MetricReaderTemporalityPreference.Cumulative,
};
this.meter = new Meter(Utils.GetCurrentMethodName());
diff --git a/test/Benchmarks/Metrics/MetricsBenchmarks.cs b/test/Benchmarks/Metrics/MetricsBenchmarks.cs
index b224944c550..8e267f32c0c 100644
--- a/test/Benchmarks/Metrics/MetricsBenchmarks.cs
+++ b/test/Benchmarks/Metrics/MetricsBenchmarks.cs
@@ -61,8 +61,8 @@ public class MetricsBenchmarks
private MeterProvider provider;
private Meter meter;
- [Params(AggregationTemporality.Cumulative, AggregationTemporality.Delta)]
- public AggregationTemporality AggregationTemporality { get; set; }
+ [Params(MetricReaderTemporalityPreference.Cumulative, MetricReaderTemporalityPreference.Delta)]
+ public MetricReaderTemporalityPreference AggregationTemporality { get; set; }
[GlobalSetup]
public void Setup()
@@ -75,7 +75,7 @@ public void Setup()
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 1000;
- metricReaderOptions.Temporality = this.AggregationTemporality;
+ metricReaderOptions.TemporalityPreference = this.AggregationTemporality;
})
.Build();
diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs
index 95a4288a33f..1f5fec6728c 100644
--- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs
+++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs
@@ -260,12 +260,12 @@ public void TestGaugeToOtlpMetric(string name, string description, string unit,
}
[Theory]
- [InlineData("test_counter", null, null, 123, null, AggregationTemporality.Cumulative, true)]
- [InlineData("test_counter", null, null, null, 123.45, AggregationTemporality.Cumulative, true)]
- [InlineData("test_counter", null, null, 123, null, AggregationTemporality.Delta, true)]
- [InlineData("test_counter", "description", "unit", 123, null, AggregationTemporality.Cumulative, true)]
- [InlineData("test_counter", null, null, 123, null, AggregationTemporality.Delta, true, "key1", "value1", "key2", 123)]
- public void TestCounterToOtlpMetric(string name, string description, string unit, long? longValue, double? doubleValue, AggregationTemporality aggregationTemporality, bool isMonotonic, params object[] keysValues)
+ [InlineData("test_counter", null, null, 123, null, MetricReaderTemporalityPreference.Cumulative, true)]
+ [InlineData("test_counter", null, null, null, 123.45, MetricReaderTemporalityPreference.Cumulative, true)]
+ [InlineData("test_counter", null, null, 123, null, MetricReaderTemporalityPreference.Delta, true)]
+ [InlineData("test_counter", "description", "unit", 123, null, MetricReaderTemporalityPreference.Cumulative, true)]
+ [InlineData("test_counter", null, null, 123, null, MetricReaderTemporalityPreference.Delta, true, "key1", "value1", "key2", 123)]
+ public void TestCounterToOtlpMetric(string name, string description, string unit, long? longValue, double? doubleValue, MetricReaderTemporalityPreference aggregationTemporality, bool isMonotonic, params object[] keysValues)
{
var metrics = new List();
@@ -274,7 +274,7 @@ public void TestCounterToOtlpMetric(string name, string description, string unit
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics, metricReaderOptions =>
{
- metricReaderOptions.Temporality = aggregationTemporality;
+ metricReaderOptions.TemporalityPreference = aggregationTemporality;
})
.Build();
@@ -315,7 +315,7 @@ public void TestCounterToOtlpMetric(string name, string description, string unit
Assert.Equal(isMonotonic, actual.Sum.IsMonotonic);
- var otlpAggregationTemporality = aggregationTemporality == AggregationTemporality.Cumulative
+ var otlpAggregationTemporality = aggregationTemporality == MetricReaderTemporalityPreference.Cumulative
? OtlpMetrics.AggregationTemporality.Cumulative
: OtlpMetrics.AggregationTemporality.Delta;
Assert.Equal(otlpAggregationTemporality, actual.Sum.AggregationTemporality);
@@ -356,12 +356,12 @@ public void TestCounterToOtlpMetric(string name, string description, string unit
}
[Theory]
- [InlineData("test_histogram", null, null, 123, null, AggregationTemporality.Cumulative)]
- [InlineData("test_histogram", null, null, null, 123.45, AggregationTemporality.Cumulative)]
- [InlineData("test_histogram", null, null, 123, null, AggregationTemporality.Delta)]
- [InlineData("test_histogram", "description", "unit", 123, null, AggregationTemporality.Cumulative)]
- [InlineData("test_histogram", null, null, 123, null, AggregationTemporality.Delta, "key1", "value1", "key2", 123)]
- public void TestHistogramToOtlpMetric(string name, string description, string unit, long? longValue, double? doubleValue, AggregationTemporality aggregationTemporality, params object[] keysValues)
+ [InlineData("test_histogram", null, null, 123, null, MetricReaderTemporalityPreference.Cumulative)]
+ [InlineData("test_histogram", null, null, null, 123.45, MetricReaderTemporalityPreference.Cumulative)]
+ [InlineData("test_histogram", null, null, 123, null, MetricReaderTemporalityPreference.Delta)]
+ [InlineData("test_histogram", "description", "unit", 123, null, MetricReaderTemporalityPreference.Cumulative)]
+ [InlineData("test_histogram", null, null, 123, null, MetricReaderTemporalityPreference.Delta, "key1", "value1", "key2", 123)]
+ public void TestHistogramToOtlpMetric(string name, string description, string unit, long? longValue, double? doubleValue, MetricReaderTemporalityPreference aggregationTemporality, params object[] keysValues)
{
var metrics = new List();
@@ -370,7 +370,7 @@ public void TestHistogramToOtlpMetric(string name, string description, string un
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics, metricReaderOptions =>
{
- metricReaderOptions.Temporality = aggregationTemporality;
+ metricReaderOptions.TemporalityPreference = aggregationTemporality;
})
.Build();
@@ -409,7 +409,7 @@ public void TestHistogramToOtlpMetric(string name, string description, string un
Assert.Null(actual.ExponentialHistogram);
Assert.Null(actual.Summary);
- var otlpAggregationTemporality = aggregationTemporality == AggregationTemporality.Cumulative
+ var otlpAggregationTemporality = aggregationTemporality == MetricReaderTemporalityPreference.Cumulative
? OtlpMetrics.AggregationTemporality.Cumulative
: OtlpMetrics.AggregationTemporality.Delta;
Assert.Equal(otlpAggregationTemporality, actual.Histogram.AggregationTemporality);
diff --git a/test/OpenTelemetry.Tests/Metrics/InMemoryExporterTests.cs b/test/OpenTelemetry.Tests/Metrics/InMemoryExporterTests.cs
index 0573ad703f6..c5337ef49a6 100644
--- a/test/OpenTelemetry.Tests/Metrics/InMemoryExporterTests.cs
+++ b/test/OpenTelemetry.Tests/Metrics/InMemoryExporterTests.cs
@@ -33,7 +33,7 @@ public void InMemoryExporterShouldDeepCopyMetricPoints()
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- metricReaderOptions.Temporality = AggregationTemporality.Delta;
+ metricReaderOptions.TemporalityPreference = MetricReaderTemporalityPreference.Delta;
})
.Build();
diff --git a/test/OpenTelemetry.Tests/Metrics/MemoryEfficiencyTests.cs b/test/OpenTelemetry.Tests/Metrics/MemoryEfficiencyTests.cs
index 646cc634249..451ec5aba80 100644
--- a/test/OpenTelemetry.Tests/Metrics/MemoryEfficiencyTests.cs
+++ b/test/OpenTelemetry.Tests/Metrics/MemoryEfficiencyTests.cs
@@ -24,9 +24,9 @@ namespace OpenTelemetry.Metrics.Tests
public class MemoryEfficiencyTests
{
[Theory]
- [InlineData(AggregationTemporality.Cumulative)]
- [InlineData(AggregationTemporality.Delta)]
- public void ExportOnlyWhenPointChanged(AggregationTemporality temporality)
+ [InlineData(MetricReaderTemporalityPreference.Cumulative)]
+ [InlineData(MetricReaderTemporalityPreference.Delta)]
+ public void ExportOnlyWhenPointChanged(MetricReaderTemporalityPreference temporality)
{
using var meter = new Meter($"{Utils.GetCurrentMethodName()}.{temporality}");
@@ -36,7 +36,7 @@ public void ExportOnlyWhenPointChanged(AggregationTemporality temporality)
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- metricReaderOptions.Temporality = temporality;
+ metricReaderOptions.TemporalityPreference = temporality;
})
.Build();
@@ -48,7 +48,7 @@ public void ExportOnlyWhenPointChanged(AggregationTemporality temporality)
exportedItems.Clear();
meterProvider.ForceFlush();
- if (temporality == AggregationTemporality.Cumulative)
+ if (temporality == MetricReaderTemporalityPreference.Cumulative)
{
Assert.Single(exportedItems);
}
diff --git a/test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs b/test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs
index a93147b6f36..3b70cf5f022 100644
--- a/test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs
+++ b/test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs
@@ -396,11 +396,11 @@ public void DuplicateInstrumentNamesFromDifferentMetersWithSameNameDifferentVers
}
[Theory]
- [InlineData(AggregationTemporality.Cumulative, true)]
- [InlineData(AggregationTemporality.Cumulative, false)]
- [InlineData(AggregationTemporality.Delta, true)]
- [InlineData(AggregationTemporality.Delta, false)]
- public void DuplicateInstrumentNamesFromDifferentMetersAreAllowed(AggregationTemporality temporality, bool hasView)
+ [InlineData(MetricReaderTemporalityPreference.Cumulative, true)]
+ [InlineData(MetricReaderTemporalityPreference.Cumulative, false)]
+ [InlineData(MetricReaderTemporalityPreference.Delta, true)]
+ [InlineData(MetricReaderTemporalityPreference.Delta, false)]
+ public void DuplicateInstrumentNamesFromDifferentMetersAreAllowed(MetricReaderTemporalityPreference temporality, bool hasView)
{
var exportedItems = new List();
@@ -411,7 +411,7 @@ public void DuplicateInstrumentNamesFromDifferentMetersAreAllowed(AggregationTem
.AddMeter(meter2.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- metricReaderOptions.Temporality = temporality;
+ metricReaderOptions.TemporalityPreference = temporality;
});
if (hasView)
@@ -532,7 +532,7 @@ public void CounterAggregationTest(bool exportDelta)
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
+ metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
})
.Build();
@@ -634,7 +634,7 @@ public void ObservableCounterAggregationTest(bool exportDelta)
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
+ metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
})
.Build();
@@ -708,7 +708,7 @@ public void ObservableCounterWithTagsAggregationTest(bool exportDelta)
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
+ metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
})
.Build();
@@ -805,7 +805,7 @@ public void ObservableCounterSpatialAggregationTest(bool exportDelta)
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
+ metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
})
.AddView("requestCount", new MetricStreamConfiguration() { TagKeys = Array.Empty() })
.Build();
@@ -844,7 +844,7 @@ public void DimensionsAreOrderInsensitiveWithSortedKeysFirst(bool exportDelta)
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
+ metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
})
.Build();
@@ -935,7 +935,7 @@ public void DimensionsAreOrderInsensitiveWithUnsortedKeysFirst(bool exportDelta)
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
+ metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
})
.Build();
@@ -1014,9 +1014,9 @@ public void DimensionsAreOrderInsensitiveWithUnsortedKeysFirst(bool exportDelta)
}
[Theory]
- [InlineData(AggregationTemporality.Cumulative)]
- [InlineData(AggregationTemporality.Delta)]
- public void TestInstrumentDisposal(AggregationTemporality temporality)
+ [InlineData(MetricReaderTemporalityPreference.Cumulative)]
+ [InlineData(MetricReaderTemporalityPreference.Delta)]
+ public void TestInstrumentDisposal(MetricReaderTemporalityPreference temporality)
{
var exportedItems = new List();
@@ -1029,7 +1029,7 @@ public void TestInstrumentDisposal(AggregationTemporality temporality)
.AddMeter(meter2.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- metricReaderOptions.Temporality = temporality;
+ metricReaderOptions.TemporalityPreference = temporality;
})
.Build();
@@ -1069,9 +1069,9 @@ public void TestInstrumentDisposal(AggregationTemporality temporality)
}
[Theory]
- [InlineData(AggregationTemporality.Cumulative)]
- [InlineData(AggregationTemporality.Delta)]
- public void TestMetricPointCap(AggregationTemporality temporality)
+ [InlineData(MetricReaderTemporalityPreference.Cumulative)]
+ [InlineData(MetricReaderTemporalityPreference.Delta)]
+ public void TestMetricPointCap(MetricReaderTemporalityPreference temporality)
{
var exportedItems = new List();
@@ -1096,7 +1096,7 @@ int MetricPointCount()
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
- metricReaderOptions.Temporality = temporality;
+ metricReaderOptions.TemporalityPreference = temporality;
})
.Build();
diff --git a/test/OpenTelemetry.Tests/Metrics/MultipleReadersTests.cs b/test/OpenTelemetry.Tests/Metrics/MultipleReadersTests.cs
index 00a5d1ae5c5..142ed9371f9 100644
--- a/test/OpenTelemetry.Tests/Metrics/MultipleReadersTests.cs
+++ b/test/OpenTelemetry.Tests/Metrics/MultipleReadersTests.cs
@@ -24,11 +24,11 @@ namespace OpenTelemetry.Metrics.Tests
public class MultipleReadersTests
{
[Theory]
- [InlineData(AggregationTemporality.Delta, false)]
- [InlineData(AggregationTemporality.Delta, true)]
- [InlineData(AggregationTemporality.Cumulative, false)]
- [InlineData(AggregationTemporality.Cumulative, true)]
- public void SdkSupportsMultipleReaders(AggregationTemporality aggregationTemporality, bool hasViews)
+ [InlineData(MetricReaderTemporalityPreference.Delta, false)]
+ [InlineData(MetricReaderTemporalityPreference.Delta, true)]
+ [InlineData(MetricReaderTemporalityPreference.Cumulative, false)]
+ [InlineData(MetricReaderTemporalityPreference.Cumulative, true)]
+ public void SdkSupportsMultipleReaders(MetricReaderTemporalityPreference aggregationTemporality, bool hasViews)
{
var exportedItems1 = new List();
var exportedItems2 = new List();
@@ -51,11 +51,11 @@ public void SdkSupportsMultipleReaders(AggregationTemporality aggregationTempora
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems1, metricReaderOptions =>
{
- metricReaderOptions.Temporality = AggregationTemporality.Delta;
+ metricReaderOptions.TemporalityPreference = MetricReaderTemporalityPreference.Delta;
})
.AddInMemoryExporter(exportedItems2, metricReaderOptions =>
{
- metricReaderOptions.Temporality = aggregationTemporality;
+ metricReaderOptions.TemporalityPreference = aggregationTemporality;
});
if (hasViews)
@@ -107,7 +107,7 @@ public void SdkSupportsMultipleReaders(AggregationTemporality aggregationTempora
// Check value exported for ObservableCounter
AssertLongSumValueForMetric(exportedItems1[2], 1000);
- if (aggregationTemporality == AggregationTemporality.Delta)
+ if (aggregationTemporality == MetricReaderTemporalityPreference.Delta)
{
AssertLongSumValueForMetric(exportedItems2[2], 1200);
}
@@ -128,7 +128,7 @@ public void SdkSupportsMultipleReaders(AggregationTemporality aggregationTempora
// Check value exported for Counter
AssertLongSumValueForMetric(exportedItems1[0], 15);
- if (aggregationTemporality == AggregationTemporality.Delta)
+ if (aggregationTemporality == MetricReaderTemporalityPreference.Delta)
{
AssertLongSumValueForMetric(exportedItems2[0], 15);
}
@@ -143,7 +143,7 @@ public void SdkSupportsMultipleReaders(AggregationTemporality aggregationTempora
// Check value exported for ObservableCounter
AssertLongSumValueForMetric(exportedItems1[2], 300);
- if (aggregationTemporality == AggregationTemporality.Delta)
+ if (aggregationTemporality == MetricReaderTemporalityPreference.Delta)
{
AssertLongSumValueForMetric(exportedItems2[2], 200);
}