MetricReader TemporalityPreference (#3153)
This commit is contained in:
parent
3bf869ab38
commit
89a740e20a
|
|
@ -71,7 +71,7 @@ namespace Examples.Console
|
||||||
exporterOptions.Protocol = options.UseGrpc ? OtlpExportProtocol.Grpc : OtlpExportProtocol.HttpProtobuf;
|
exporterOptions.Protocol = options.UseGrpc ? OtlpExportProtocol.Grpc : OtlpExportProtocol.HttpProtobuf;
|
||||||
|
|
||||||
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds;
|
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds;
|
||||||
metricReaderOptions.Temporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
|
metricReaderOptions.TemporalityPreference = options.IsDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -82,7 +82,7 @@ namespace Examples.Console
|
||||||
exporterOptions.Targets = ConsoleExporterOutputTargets.Console;
|
exporterOptions.Targets = ConsoleExporterOutputTargets.Console;
|
||||||
|
|
||||||
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds;
|
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds;
|
||||||
metricReaderOptions.Temporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
|
metricReaderOptions.TemporalityPreference = options.IsDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ namespace OpenTelemetry.Exporter
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Exporter of OpenTelemetry metrics to Prometheus.
|
/// Exporter of OpenTelemetry metrics to Prometheus.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AggregationTemporality(AggregationTemporality.Cumulative)]
|
|
||||||
[ExportModes(ExportModes.Pull)]
|
[ExportModes(ExportModes.Pull)]
|
||||||
public class PrometheusExporter : BaseExporter<Metric>, IPullMetricExporter
|
public class PrometheusExporter : BaseExporter<Metric>, IPullMetricExporter
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ namespace OpenTelemetry.Metrics
|
||||||
|
|
||||||
var exporter = new PrometheusExporter(options);
|
var exporter = new PrometheusExporter(options);
|
||||||
var reader = new BaseExportingMetricReader(exporter);
|
var reader = new BaseExportingMetricReader(exporter);
|
||||||
|
reader.TemporalityPreference = MetricReaderTemporalityPreference.Cumulative;
|
||||||
|
|
||||||
return builder.AddReader(reader);
|
return builder.AddReader(reader);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,14 @@ OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration
|
||||||
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.get -> double[]
|
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.get -> double[]
|
||||||
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.set -> void
|
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.set -> void
|
||||||
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.ExplicitBucketHistogramConfiguration() -> 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
|
||||||
OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderOptions() -> void
|
OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderOptions() -> void
|
||||||
OpenTelemetry.Metrics.MetricReaderOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions
|
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
|
||||||
OpenTelemetry.Metrics.AggregationTemporality.Cumulative = 1 -> OpenTelemetry.Metrics.AggregationTemporality
|
OpenTelemetry.Metrics.AggregationTemporality.Cumulative = 1 -> OpenTelemetry.Metrics.AggregationTemporality
|
||||||
OpenTelemetry.Metrics.AggregationTemporality.Delta = 2 -> 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
|
||||||
OpenTelemetry.Metrics.BaseExportingMetricReader.BaseExportingMetricReader(OpenTelemetry.BaseExporter<OpenTelemetry.Metrics.Metric> exporter) -> void
|
OpenTelemetry.Metrics.BaseExportingMetricReader.BaseExportingMetricReader(OpenTelemetry.BaseExporter<OpenTelemetry.Metrics.Metric> exporter) -> void
|
||||||
OpenTelemetry.Metrics.BaseExportingMetricReader.SupportedExportModes.get -> OpenTelemetry.Metrics.ExportModes
|
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.Dispose() -> void
|
||||||
OpenTelemetry.Metrics.MetricReader.MetricReader() -> void
|
OpenTelemetry.Metrics.MetricReader.MetricReader() -> void
|
||||||
OpenTelemetry.Metrics.MetricReader.Shutdown(int timeoutMilliseconds = -1) -> bool
|
OpenTelemetry.Metrics.MetricReader.Shutdown(int timeoutMilliseconds = -1) -> bool
|
||||||
OpenTelemetry.Metrics.MetricReader.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
|
OpenTelemetry.Metrics.MetricReaderOptions.TemporalityPreference.get -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
|
||||||
OpenTelemetry.Metrics.MetricReader.Temporality.set -> void
|
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
|
||||||
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.get -> string
|
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.get -> string
|
||||||
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.set -> void
|
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.set -> void
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,14 @@ OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration
|
||||||
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.get -> double[]
|
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.get -> double[]
|
||||||
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.set -> void
|
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.set -> void
|
||||||
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.ExplicitBucketHistogramConfiguration() -> 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
|
||||||
OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderOptions() -> void
|
OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderOptions() -> void
|
||||||
OpenTelemetry.Metrics.MetricReaderOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions
|
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
|
||||||
OpenTelemetry.Metrics.AggregationTemporality.Cumulative = 1 -> OpenTelemetry.Metrics.AggregationTemporality
|
OpenTelemetry.Metrics.AggregationTemporality.Cumulative = 1 -> OpenTelemetry.Metrics.AggregationTemporality
|
||||||
OpenTelemetry.Metrics.AggregationTemporality.Delta = 2 -> 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
|
||||||
OpenTelemetry.Metrics.BaseExportingMetricReader.BaseExportingMetricReader(OpenTelemetry.BaseExporter<OpenTelemetry.Metrics.Metric> exporter) -> void
|
OpenTelemetry.Metrics.BaseExportingMetricReader.BaseExportingMetricReader(OpenTelemetry.BaseExporter<OpenTelemetry.Metrics.Metric> exporter) -> void
|
||||||
OpenTelemetry.Metrics.BaseExportingMetricReader.SupportedExportModes.get -> OpenTelemetry.Metrics.ExportModes
|
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.Dispose() -> void
|
||||||
OpenTelemetry.Metrics.MetricReader.MetricReader() -> void
|
OpenTelemetry.Metrics.MetricReader.MetricReader() -> void
|
||||||
OpenTelemetry.Metrics.MetricReader.Shutdown(int timeoutMilliseconds = -1) -> bool
|
OpenTelemetry.Metrics.MetricReader.Shutdown(int timeoutMilliseconds = -1) -> bool
|
||||||
OpenTelemetry.Metrics.MetricReader.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
|
OpenTelemetry.Metrics.MetricReaderOptions.TemporalityPreference.get -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
|
||||||
OpenTelemetry.Metrics.MetricReader.Temporality.set -> void
|
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
|
||||||
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.get -> string
|
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.get -> string
|
||||||
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.set -> void
|
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.set -> void
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,19 @@
|
||||||
|
|
||||||
## Unreleased
|
## 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
|
* Fix issue where `ExplicitBucketHistogramConfiguration` could be used to
|
||||||
configure metric streams for instruments that are not histograms. Currently,
|
configure metric streams for instruments that are not histograms. Currently,
|
||||||
it is not possible to change the aggregation of an instrument with views. This
|
it is not possible to change the aggregation of an instrument with views. This
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ internal static class PeriodicExportingMetricReaderHelper
|
||||||
|
|
||||||
var metricReader = new PeriodicExportingMetricReader(exporter, exportInterval, exportTimeout)
|
var metricReader = new PeriodicExportingMetricReader(exporter, exportInterval, exportTimeout)
|
||||||
{
|
{
|
||||||
Temporality = options.Temporality,
|
TemporalityPreference = options.TemporalityPreference,
|
||||||
};
|
};
|
||||||
|
|
||||||
return metricReader;
|
return metricReader;
|
||||||
|
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
// <copyright file="AggregationTemporalityAttribute.cs" company="OpenTelemetry Authors">
|
|
||||||
// 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.
|
|
||||||
// </copyright>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -45,14 +45,7 @@ namespace OpenTelemetry.Metrics
|
||||||
this.exporter = exporter;
|
this.exporter = exporter;
|
||||||
|
|
||||||
var exportorType = exporter.GetType();
|
var exportorType = exporter.GetType();
|
||||||
var attributes = exportorType.GetCustomAttributes(typeof(AggregationTemporalityAttribute), true);
|
var attributes = exportorType.GetCustomAttributes(typeof(ExportModesAttribute), true);
|
||||||
if (attributes.Length > 0)
|
|
||||||
{
|
|
||||||
var attr = (AggregationTemporalityAttribute)attributes[attributes.Length - 1];
|
|
||||||
this.Temporality = attr.Temporality;
|
|
||||||
}
|
|
||||||
|
|
||||||
attributes = exportorType.GetCustomAttributes(typeof(ExportModesAttribute), true);
|
|
||||||
if (attributes.Length > 0)
|
if (attributes.Length > 0)
|
||||||
{
|
{
|
||||||
var attr = (ExportModesAttribute)attributes[attributes.Length - 1];
|
var attr = (ExportModesAttribute)attributes[attributes.Length - 1];
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Diagnostics.Metrics;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using OpenTelemetry.Internal;
|
using OpenTelemetry.Internal;
|
||||||
|
|
@ -27,35 +28,74 @@ namespace OpenTelemetry.Metrics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract partial class MetricReader : IDisposable
|
public abstract partial class MetricReader : IDisposable
|
||||||
{
|
{
|
||||||
private const AggregationTemporality AggregationTemporalityUnspecified = (AggregationTemporality)0;
|
private const MetricReaderTemporalityPreference MetricReaderTemporalityPreferenceUnspecified = (MetricReaderTemporalityPreference)0;
|
||||||
|
|
||||||
|
private static Func<Type, AggregationTemporality> cumulativeTemporatlityPreferenceFunc =
|
||||||
|
(instrumentType) => AggregationTemporality.Cumulative;
|
||||||
|
|
||||||
|
private static Func<Type, AggregationTemporality> 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 newTaskLock = new();
|
||||||
private readonly object onCollectLock = new();
|
private readonly object onCollectLock = new();
|
||||||
private readonly TaskCompletionSource<bool> shutdownTcs = new();
|
private readonly TaskCompletionSource<bool> shutdownTcs = new();
|
||||||
private AggregationTemporality temporality = AggregationTemporalityUnspecified;
|
private MetricReaderTemporalityPreference temporalityPreference = MetricReaderTemporalityPreferenceUnspecified;
|
||||||
|
private Func<Type, AggregationTemporality> temporatlityFunc = cumulativeTemporatlityPreferenceFunc;
|
||||||
private int shutdownCount;
|
private int shutdownCount;
|
||||||
private TaskCompletionSource<bool> collectionTcs;
|
private TaskCompletionSource<bool> collectionTcs;
|
||||||
private BaseProvider parentProvider;
|
private BaseProvider parentProvider;
|
||||||
|
|
||||||
public AggregationTemporality Temporality
|
public MetricReaderTemporalityPreference TemporalityPreference
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (this.temporality == AggregationTemporalityUnspecified)
|
if (this.temporalityPreference == MetricReaderTemporalityPreferenceUnspecified)
|
||||||
{
|
{
|
||||||
this.temporality = AggregationTemporality.Cumulative;
|
this.temporalityPreference = MetricReaderTemporalityPreference.Cumulative;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.temporality;
|
return this.temporalityPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
set
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,11 @@ namespace OpenTelemetry.Metrics
|
||||||
private Metric[] metricsCurrentBatch;
|
private Metric[] metricsCurrentBatch;
|
||||||
private int metricIndex = -1;
|
private int metricIndex = -1;
|
||||||
|
|
||||||
|
internal AggregationTemporality GetAggregationTemporality(Type instrumentType)
|
||||||
|
{
|
||||||
|
return this.temporatlityFunc(instrumentType);
|
||||||
|
}
|
||||||
|
|
||||||
internal Metric AddMetricWithNoViews(Instrument instrument)
|
internal Metric AddMetricWithNoViews(Instrument instrument)
|
||||||
{
|
{
|
||||||
var metricStreamIdentity = new MetricStreamIdentity(instrument, metricStreamConfiguration: null);
|
var metricStreamIdentity = new MetricStreamIdentity(instrument, metricStreamConfiguration: null);
|
||||||
|
|
@ -66,7 +71,7 @@ namespace OpenTelemetry.Metrics
|
||||||
Metric metric = null;
|
Metric metric = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
metric = new Metric(metricStreamIdentity, this.Temporality, this.maxMetricPointsPerMetricStream);
|
metric = new Metric(metricStreamIdentity, this.GetAggregationTemporality(metricStreamIdentity.InstrumentType), this.maxMetricPointsPerMetricStream);
|
||||||
}
|
}
|
||||||
catch (NotSupportedException nse)
|
catch (NotSupportedException nse)
|
||||||
{
|
{
|
||||||
|
|
@ -152,7 +157,7 @@ namespace OpenTelemetry.Metrics
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Metric metric;
|
Metric metric;
|
||||||
metric = new Metric(metricStreamIdentity, this.Temporality, this.maxMetricPointsPerMetricStream, metricStreamIdentity.HistogramBucketBounds, metricStreamIdentity.TagKeys);
|
metric = new Metric(metricStreamIdentity, this.GetAggregationTemporality(metricStreamIdentity.InstrumentType), this.maxMetricPointsPerMetricStream, metricStreamIdentity.HistogramBucketBounds, metricStreamIdentity.TagKeys);
|
||||||
|
|
||||||
this.instrumentIdentityToMetric[metricStreamIdentity] = metric;
|
this.instrumentIdentityToMetric[metricStreamIdentity] = metric;
|
||||||
this.metrics[index] = metric;
|
this.metrics[index] = metric;
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,9 @@ namespace OpenTelemetry.Metrics;
|
||||||
public class MetricReaderOptions
|
public class MetricReaderOptions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the AggregationTemporality used for Histogram
|
/// Gets or sets the <see cref="MetricReaderTemporalityPreference" />.
|
||||||
/// and Sum metrics.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AggregationTemporality Temporality { get; set; } = AggregationTemporality.Cumulative;
|
public MetricReaderTemporalityPreference TemporalityPreference { get; set; } = MetricReaderTemporalityPreference.Cumulative;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="PeriodicExportingMetricReaderOptions" /> options.
|
/// Gets the <see cref="PeriodicExportingMetricReaderOptions" /> options.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
// <copyright file="MetricReaderTemporalityPreference.cs" company="OpenTelemetry Authors">
|
||||||
|
// 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.
|
||||||
|
// </copyright>
|
||||||
|
|
||||||
|
namespace OpenTelemetry.Metrics;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Defines the behavior of a <see cref="MetricReader" />
|
||||||
|
/// with respect to <see cref="AggregationTemporality" />.
|
||||||
|
/// </summary>
|
||||||
|
public enum MetricReaderTemporalityPreference
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// All aggregations are performed using cumulative temporatlity.
|
||||||
|
/// </summary>
|
||||||
|
Cumulative = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// All measurements that are monotnic in nature are aggregated using delta temporality.
|
||||||
|
/// Aggregations of non-monotonic measurements use cumulative temporality.
|
||||||
|
/// </summary>
|
||||||
|
Delta = 2,
|
||||||
|
}
|
||||||
|
|
@ -88,7 +88,7 @@ namespace Benchmarks.Metrics
|
||||||
|
|
||||||
this.reader = new BaseExportingMetricReader(metricExporter)
|
this.reader = new BaseExportingMetricReader(metricExporter)
|
||||||
{
|
{
|
||||||
Temporality = AggregationTemporality.Cumulative,
|
TemporalityPreference = MetricReaderTemporalityPreference.Cumulative,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.meter = new Meter(Utils.GetCurrentMethodName());
|
this.meter = new Meter(Utils.GetCurrentMethodName());
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,8 @@ namespace Benchmarks.Metrics
|
||||||
private MeterProvider provider;
|
private MeterProvider provider;
|
||||||
private Meter meter;
|
private Meter meter;
|
||||||
|
|
||||||
[Params(AggregationTemporality.Cumulative, AggregationTemporality.Delta)]
|
[Params(MetricReaderTemporalityPreference.Cumulative, MetricReaderTemporalityPreference.Delta)]
|
||||||
public AggregationTemporality AggregationTemporality { get; set; }
|
public MetricReaderTemporalityPreference AggregationTemporality { get; set; }
|
||||||
|
|
||||||
[GlobalSetup]
|
[GlobalSetup]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
|
|
@ -75,7 +75,7 @@ namespace Benchmarks.Metrics
|
||||||
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 1000;
|
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 1000;
|
||||||
metricReaderOptions.Temporality = this.AggregationTemporality;
|
metricReaderOptions.TemporalityPreference = this.AggregationTemporality;
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -260,12 +260,12 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("test_counter", null, null, 123, null, AggregationTemporality.Cumulative, true)]
|
[InlineData("test_counter", null, null, 123, null, MetricReaderTemporalityPreference.Cumulative, true)]
|
||||||
[InlineData("test_counter", null, null, null, 123.45, AggregationTemporality.Cumulative, true)]
|
[InlineData("test_counter", null, null, null, 123.45, MetricReaderTemporalityPreference.Cumulative, true)]
|
||||||
[InlineData("test_counter", null, null, 123, null, AggregationTemporality.Delta, true)]
|
[InlineData("test_counter", null, null, 123, null, MetricReaderTemporalityPreference.Delta, true)]
|
||||||
[InlineData("test_counter", "description", "unit", 123, null, AggregationTemporality.Cumulative, true)]
|
[InlineData("test_counter", "description", "unit", 123, null, MetricReaderTemporalityPreference.Cumulative, true)]
|
||||||
[InlineData("test_counter", null, null, 123, null, AggregationTemporality.Delta, true, "key1", "value1", "key2", 123)]
|
[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, AggregationTemporality aggregationTemporality, bool isMonotonic, params object[] keysValues)
|
public void TestCounterToOtlpMetric(string name, string description, string unit, long? longValue, double? doubleValue, MetricReaderTemporalityPreference aggregationTemporality, bool isMonotonic, params object[] keysValues)
|
||||||
{
|
{
|
||||||
var metrics = new List<Metric>();
|
var metrics = new List<Metric>();
|
||||||
|
|
||||||
|
|
@ -274,7 +274,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
||||||
.AddMeter(meter.Name)
|
.AddMeter(meter.Name)
|
||||||
.AddInMemoryExporter(metrics, metricReaderOptions =>
|
.AddInMemoryExporter(metrics, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = aggregationTemporality;
|
metricReaderOptions.TemporalityPreference = aggregationTemporality;
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
@ -315,7 +315,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
||||||
|
|
||||||
Assert.Equal(isMonotonic, actual.Sum.IsMonotonic);
|
Assert.Equal(isMonotonic, actual.Sum.IsMonotonic);
|
||||||
|
|
||||||
var otlpAggregationTemporality = aggregationTemporality == AggregationTemporality.Cumulative
|
var otlpAggregationTemporality = aggregationTemporality == MetricReaderTemporalityPreference.Cumulative
|
||||||
? OtlpMetrics.AggregationTemporality.Cumulative
|
? OtlpMetrics.AggregationTemporality.Cumulative
|
||||||
: OtlpMetrics.AggregationTemporality.Delta;
|
: OtlpMetrics.AggregationTemporality.Delta;
|
||||||
Assert.Equal(otlpAggregationTemporality, actual.Sum.AggregationTemporality);
|
Assert.Equal(otlpAggregationTemporality, actual.Sum.AggregationTemporality);
|
||||||
|
|
@ -356,12 +356,12 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("test_histogram", null, null, 123, null, AggregationTemporality.Cumulative)]
|
[InlineData("test_histogram", null, null, 123, null, MetricReaderTemporalityPreference.Cumulative)]
|
||||||
[InlineData("test_histogram", null, null, null, 123.45, AggregationTemporality.Cumulative)]
|
[InlineData("test_histogram", null, null, null, 123.45, MetricReaderTemporalityPreference.Cumulative)]
|
||||||
[InlineData("test_histogram", null, null, 123, null, AggregationTemporality.Delta)]
|
[InlineData("test_histogram", null, null, 123, null, MetricReaderTemporalityPreference.Delta)]
|
||||||
[InlineData("test_histogram", "description", "unit", 123, null, AggregationTemporality.Cumulative)]
|
[InlineData("test_histogram", "description", "unit", 123, null, MetricReaderTemporalityPreference.Cumulative)]
|
||||||
[InlineData("test_histogram", null, null, 123, null, AggregationTemporality.Delta, "key1", "value1", "key2", 123)]
|
[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, AggregationTemporality aggregationTemporality, params object[] keysValues)
|
public void TestHistogramToOtlpMetric(string name, string description, string unit, long? longValue, double? doubleValue, MetricReaderTemporalityPreference aggregationTemporality, params object[] keysValues)
|
||||||
{
|
{
|
||||||
var metrics = new List<Metric>();
|
var metrics = new List<Metric>();
|
||||||
|
|
||||||
|
|
@ -370,7 +370,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
||||||
.AddMeter(meter.Name)
|
.AddMeter(meter.Name)
|
||||||
.AddInMemoryExporter(metrics, metricReaderOptions =>
|
.AddInMemoryExporter(metrics, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = aggregationTemporality;
|
metricReaderOptions.TemporalityPreference = aggregationTemporality;
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
@ -409,7 +409,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
||||||
Assert.Null(actual.ExponentialHistogram);
|
Assert.Null(actual.ExponentialHistogram);
|
||||||
Assert.Null(actual.Summary);
|
Assert.Null(actual.Summary);
|
||||||
|
|
||||||
var otlpAggregationTemporality = aggregationTemporality == AggregationTemporality.Cumulative
|
var otlpAggregationTemporality = aggregationTemporality == MetricReaderTemporalityPreference.Cumulative
|
||||||
? OtlpMetrics.AggregationTemporality.Cumulative
|
? OtlpMetrics.AggregationTemporality.Cumulative
|
||||||
: OtlpMetrics.AggregationTemporality.Delta;
|
: OtlpMetrics.AggregationTemporality.Delta;
|
||||||
Assert.Equal(otlpAggregationTemporality, actual.Histogram.AggregationTemporality);
|
Assert.Equal(otlpAggregationTemporality, actual.Histogram.AggregationTemporality);
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
.AddMeter(meter.Name)
|
.AddMeter(meter.Name)
|
||||||
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = AggregationTemporality.Delta;
|
metricReaderOptions.TemporalityPreference = MetricReaderTemporalityPreference.Delta;
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
public class MemoryEfficiencyTests
|
public class MemoryEfficiencyTests
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AggregationTemporality.Cumulative)]
|
[InlineData(MetricReaderTemporalityPreference.Cumulative)]
|
||||||
[InlineData(AggregationTemporality.Delta)]
|
[InlineData(MetricReaderTemporalityPreference.Delta)]
|
||||||
public void ExportOnlyWhenPointChanged(AggregationTemporality temporality)
|
public void ExportOnlyWhenPointChanged(MetricReaderTemporalityPreference temporality)
|
||||||
{
|
{
|
||||||
using var meter = new Meter($"{Utils.GetCurrentMethodName()}.{temporality}");
|
using var meter = new Meter($"{Utils.GetCurrentMethodName()}.{temporality}");
|
||||||
|
|
||||||
|
|
@ -36,7 +36,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
.AddMeter(meter.Name)
|
.AddMeter(meter.Name)
|
||||||
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = temporality;
|
metricReaderOptions.TemporalityPreference = temporality;
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
|
|
||||||
exportedItems.Clear();
|
exportedItems.Clear();
|
||||||
meterProvider.ForceFlush();
|
meterProvider.ForceFlush();
|
||||||
if (temporality == AggregationTemporality.Cumulative)
|
if (temporality == MetricReaderTemporalityPreference.Cumulative)
|
||||||
{
|
{
|
||||||
Assert.Single(exportedItems);
|
Assert.Single(exportedItems);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -396,11 +396,11 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AggregationTemporality.Cumulative, true)]
|
[InlineData(MetricReaderTemporalityPreference.Cumulative, true)]
|
||||||
[InlineData(AggregationTemporality.Cumulative, false)]
|
[InlineData(MetricReaderTemporalityPreference.Cumulative, false)]
|
||||||
[InlineData(AggregationTemporality.Delta, true)]
|
[InlineData(MetricReaderTemporalityPreference.Delta, true)]
|
||||||
[InlineData(AggregationTemporality.Delta, false)]
|
[InlineData(MetricReaderTemporalityPreference.Delta, false)]
|
||||||
public void DuplicateInstrumentNamesFromDifferentMetersAreAllowed(AggregationTemporality temporality, bool hasView)
|
public void DuplicateInstrumentNamesFromDifferentMetersAreAllowed(MetricReaderTemporalityPreference temporality, bool hasView)
|
||||||
{
|
{
|
||||||
var exportedItems = new List<Metric>();
|
var exportedItems = new List<Metric>();
|
||||||
|
|
||||||
|
|
@ -411,7 +411,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
.AddMeter(meter2.Name)
|
.AddMeter(meter2.Name)
|
||||||
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = temporality;
|
metricReaderOptions.TemporalityPreference = temporality;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (hasView)
|
if (hasView)
|
||||||
|
|
@ -532,7 +532,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
.AddMeter(meter.Name)
|
.AddMeter(meter.Name)
|
||||||
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
|
metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
@ -634,7 +634,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
.AddMeter(meter.Name)
|
.AddMeter(meter.Name)
|
||||||
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
|
metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
@ -708,7 +708,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
.AddMeter(meter.Name)
|
.AddMeter(meter.Name)
|
||||||
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
|
metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
@ -805,7 +805,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
.AddMeter(meter.Name)
|
.AddMeter(meter.Name)
|
||||||
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
|
metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
|
||||||
})
|
})
|
||||||
.AddView("requestCount", new MetricStreamConfiguration() { TagKeys = Array.Empty<string>() })
|
.AddView("requestCount", new MetricStreamConfiguration() { TagKeys = Array.Empty<string>() })
|
||||||
.Build();
|
.Build();
|
||||||
|
|
@ -844,7 +844,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
.AddMeter(meter.Name)
|
.AddMeter(meter.Name)
|
||||||
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
|
metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
@ -935,7 +935,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
.AddMeter(meter.Name)
|
.AddMeter(meter.Name)
|
||||||
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
|
metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
@ -1014,9 +1014,9 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AggregationTemporality.Cumulative)]
|
[InlineData(MetricReaderTemporalityPreference.Cumulative)]
|
||||||
[InlineData(AggregationTemporality.Delta)]
|
[InlineData(MetricReaderTemporalityPreference.Delta)]
|
||||||
public void TestInstrumentDisposal(AggregationTemporality temporality)
|
public void TestInstrumentDisposal(MetricReaderTemporalityPreference temporality)
|
||||||
{
|
{
|
||||||
var exportedItems = new List<Metric>();
|
var exportedItems = new List<Metric>();
|
||||||
|
|
||||||
|
|
@ -1029,7 +1029,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
.AddMeter(meter2.Name)
|
.AddMeter(meter2.Name)
|
||||||
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = temporality;
|
metricReaderOptions.TemporalityPreference = temporality;
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
@ -1069,9 +1069,9 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AggregationTemporality.Cumulative)]
|
[InlineData(MetricReaderTemporalityPreference.Cumulative)]
|
||||||
[InlineData(AggregationTemporality.Delta)]
|
[InlineData(MetricReaderTemporalityPreference.Delta)]
|
||||||
public void TestMetricPointCap(AggregationTemporality temporality)
|
public void TestMetricPointCap(MetricReaderTemporalityPreference temporality)
|
||||||
{
|
{
|
||||||
var exportedItems = new List<Metric>();
|
var exportedItems = new List<Metric>();
|
||||||
|
|
||||||
|
|
@ -1096,7 +1096,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
.AddMeter(meter.Name)
|
.AddMeter(meter.Name)
|
||||||
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = temporality;
|
metricReaderOptions.TemporalityPreference = temporality;
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,11 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
public class MultipleReadersTests
|
public class MultipleReadersTests
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AggregationTemporality.Delta, false)]
|
[InlineData(MetricReaderTemporalityPreference.Delta, false)]
|
||||||
[InlineData(AggregationTemporality.Delta, true)]
|
[InlineData(MetricReaderTemporalityPreference.Delta, true)]
|
||||||
[InlineData(AggregationTemporality.Cumulative, false)]
|
[InlineData(MetricReaderTemporalityPreference.Cumulative, false)]
|
||||||
[InlineData(AggregationTemporality.Cumulative, true)]
|
[InlineData(MetricReaderTemporalityPreference.Cumulative, true)]
|
||||||
public void SdkSupportsMultipleReaders(AggregationTemporality aggregationTemporality, bool hasViews)
|
public void SdkSupportsMultipleReaders(MetricReaderTemporalityPreference aggregationTemporality, bool hasViews)
|
||||||
{
|
{
|
||||||
var exportedItems1 = new List<Metric>();
|
var exportedItems1 = new List<Metric>();
|
||||||
var exportedItems2 = new List<Metric>();
|
var exportedItems2 = new List<Metric>();
|
||||||
|
|
@ -51,11 +51,11 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
.AddMeter(meter.Name)
|
.AddMeter(meter.Name)
|
||||||
.AddInMemoryExporter(exportedItems1, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems1, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = AggregationTemporality.Delta;
|
metricReaderOptions.TemporalityPreference = MetricReaderTemporalityPreference.Delta;
|
||||||
})
|
})
|
||||||
.AddInMemoryExporter(exportedItems2, metricReaderOptions =>
|
.AddInMemoryExporter(exportedItems2, metricReaderOptions =>
|
||||||
{
|
{
|
||||||
metricReaderOptions.Temporality = aggregationTemporality;
|
metricReaderOptions.TemporalityPreference = aggregationTemporality;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (hasViews)
|
if (hasViews)
|
||||||
|
|
@ -107,7 +107,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
|
|
||||||
// Check value exported for ObservableCounter
|
// Check value exported for ObservableCounter
|
||||||
AssertLongSumValueForMetric(exportedItems1[2], 1000);
|
AssertLongSumValueForMetric(exportedItems1[2], 1000);
|
||||||
if (aggregationTemporality == AggregationTemporality.Delta)
|
if (aggregationTemporality == MetricReaderTemporalityPreference.Delta)
|
||||||
{
|
{
|
||||||
AssertLongSumValueForMetric(exportedItems2[2], 1200);
|
AssertLongSumValueForMetric(exportedItems2[2], 1200);
|
||||||
}
|
}
|
||||||
|
|
@ -128,7 +128,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
|
|
||||||
// Check value exported for Counter
|
// Check value exported for Counter
|
||||||
AssertLongSumValueForMetric(exportedItems1[0], 15);
|
AssertLongSumValueForMetric(exportedItems1[0], 15);
|
||||||
if (aggregationTemporality == AggregationTemporality.Delta)
|
if (aggregationTemporality == MetricReaderTemporalityPreference.Delta)
|
||||||
{
|
{
|
||||||
AssertLongSumValueForMetric(exportedItems2[0], 15);
|
AssertLongSumValueForMetric(exportedItems2[0], 15);
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +143,7 @@ namespace OpenTelemetry.Metrics.Tests
|
||||||
|
|
||||||
// Check value exported for ObservableCounter
|
// Check value exported for ObservableCounter
|
||||||
AssertLongSumValueForMetric(exportedItems1[2], 300);
|
AssertLongSumValueForMetric(exportedItems1[2], 300);
|
||||||
if (aggregationTemporality == AggregationTemporality.Delta)
|
if (aggregationTemporality == MetricReaderTemporalityPreference.Delta)
|
||||||
{
|
{
|
||||||
AssertLongSumValueForMetric(exportedItems2[2], 200);
|
AssertLongSumValueForMetric(exportedItems2[2], 200);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue