diff --git a/src/OpenTelemetry.Api/Metrics/Counter.cs b/src/OpenTelemetry.Api/Metrics/CounterMetric.cs similarity index 91% rename from src/OpenTelemetry.Api/Metrics/Counter.cs rename to src/OpenTelemetry.Api/Metrics/CounterMetric.cs index 76f527465f7..a94136220c3 100644 --- a/src/OpenTelemetry.Api/Metrics/Counter.cs +++ b/src/OpenTelemetry.Api/Metrics/CounterMetric.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +24,7 @@ namespace OpenTelemetry.Metrics /// Counter instrument. /// /// The type of counter. Only long and double are supported now. - public abstract class Counter + public abstract class CounterMetric where T : struct { /// @@ -64,13 +64,13 @@ public abstract class Counter /// /// The labelset from which handle should be constructed. /// The handle. - public abstract CounterHandle GetHandle(LabelSet labelset); + public abstract CounterMetricHandle GetHandle(LabelSet labelset); /// /// Gets the handle with given labels. /// /// The labels or dimensions associated with this value. /// The handle. - public abstract CounterHandle GetHandle(IEnumerable> labels); + public abstract CounterMetricHandle GetHandle(IEnumerable> labels); } } diff --git a/src/OpenTelemetry.Api/Metrics/CounterHandle.cs b/src/OpenTelemetry.Api/Metrics/CounterMetricHandle.cs similarity index 92% rename from src/OpenTelemetry.Api/Metrics/CounterHandle.cs rename to src/OpenTelemetry.Api/Metrics/CounterMetricHandle.cs index 7a40451e440..c9a5ab43904 100644 --- a/src/OpenTelemetry.Api/Metrics/CounterHandle.cs +++ b/src/OpenTelemetry.Api/Metrics/CounterMetricHandle.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ namespace OpenTelemetry.Metrics /// Handle to the metrics counter with the defined . /// /// The type of counter. Only long and double are supported now. - public abstract class CounterHandle + public abstract class CounterMetricHandle where T : struct { /// diff --git a/src/OpenTelemetry.Api/Metrics/Measure.cs b/src/OpenTelemetry.Api/Metrics/MeasureMetric.cs similarity index 91% rename from src/OpenTelemetry.Api/Metrics/Measure.cs rename to src/OpenTelemetry.Api/Metrics/MeasureMetric.cs index c93154dd58b..7215a444ba8 100644 --- a/src/OpenTelemetry.Api/Metrics/Measure.cs +++ b/src/OpenTelemetry.Api/Metrics/MeasureMetric.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +24,7 @@ namespace OpenTelemetry.Metrics /// Measure instrument. /// /// The type of counter. Only long and double are supported now. - public abstract class Measure + public abstract class MeasureMetric where T : struct { /// @@ -64,13 +64,13 @@ public abstract class Measure /// /// The labelset from which handle should be constructed. /// The handle. - public abstract MeasureHandle GetHandle(LabelSet labelset); + public abstract MeasureMetricHandle GetHandle(LabelSet labelset); /// /// Gets the handle with given labelset. /// /// The labels or dimensions associated with this value. /// The handle. - public abstract MeasureHandle GetHandle(IEnumerable> labels); + public abstract MeasureMetricHandle GetHandle(IEnumerable> labels); } } diff --git a/src/OpenTelemetry.Api/Metrics/MeasureHandle.cs b/src/OpenTelemetry.Api/Metrics/MeasureMetricHandle.cs similarity index 92% rename from src/OpenTelemetry.Api/Metrics/MeasureHandle.cs rename to src/OpenTelemetry.Api/Metrics/MeasureMetricHandle.cs index bd68639e4de..0c27accb103 100644 --- a/src/OpenTelemetry.Api/Metrics/MeasureHandle.cs +++ b/src/OpenTelemetry.Api/Metrics/MeasureMetricHandle.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ namespace OpenTelemetry.Metrics /// Handle to the metrics Measure with the defined . /// /// The type of Measure. Only long and double are supported now. - public abstract class MeasureHandle + public abstract class MeasureMetricHandle where T : struct { /// diff --git a/src/OpenTelemetry.Api/Metrics/Meter.cs b/src/OpenTelemetry.Api/Metrics/Meter.cs index f7ce4bb89ed..fcd19a33aab 100644 --- a/src/OpenTelemetry.Api/Metrics/Meter.cs +++ b/src/OpenTelemetry.Api/Metrics/Meter.cs @@ -29,7 +29,7 @@ public abstract class Meter /// The name of the counter. /// indicates if only positive values are expected. /// The counter instance. - public abstract Counter CreateInt64Counter(string name, bool monotonic = true); + public abstract CounterMetric CreateInt64Counter(string name, bool monotonic = true); /// /// Creates double counter with given name. @@ -37,23 +37,7 @@ public abstract class Meter /// indicates if only positive values are expected. /// The name of the counter. /// The counter instance. - public abstract Counter CreateDoubleCounter(string name, bool monotonic = true); - - /// - /// Creates Int64 Gauge with given name. - /// - /// The name of the counter. - /// indicates if only positive values are expected. - /// The Gauge instance. - public abstract Gauge CreateInt64Gauge(string name, bool monotonic = false); - - /// - /// Creates double Gauge with given name. - /// - /// The name of the counter. - /// indicates if only positive values are expected. - /// The Gauge instance. - public abstract Gauge CreateDoubleGauge(string name, bool monotonic = false); + public abstract CounterMetric CreateDoubleCounter(string name, bool monotonic = true); /// /// Creates Int64 Measure with given name. @@ -61,7 +45,7 @@ public abstract class Meter /// The name of the measure. /// indicates if only positive values are expected. /// The measure instance. - public abstract Measure CreateInt64Measure(string name, bool absolute = true); + public abstract MeasureMetric CreateInt64Measure(string name, bool absolute = true); /// /// Creates double Measure with given name. @@ -69,7 +53,23 @@ public abstract class Meter /// The name of the measure. /// indicates if only positive values are expected. /// The measure instance. - public abstract Measure CreateDoubleMeasure(string name, bool absolute = true); + public abstract MeasureMetric CreateDoubleMeasure(string name, bool absolute = true); + + /// + /// Creates Int64 Observer with given name. + /// + /// The name of the observer. + /// indicates if only positive values are expected. + /// The observer instance. + public abstract ObserverMetric CreateInt64Observer(string name, bool absolute = true); + + /// + /// Creates a double Observer with given name. + /// + /// The name of the observer. + /// indicates if only positive values are expected. + /// The observer instance. + public abstract ObserverMetric CreateDoubleObserver(string name, bool absolute = true); /// /// Constructs or retrieves the from the given label key-value pairs. diff --git a/src/OpenTelemetry.Api/Metrics/NoOpCounter.cs b/src/OpenTelemetry.Api/Metrics/NoOpCounterMetric.cs similarity index 68% rename from src/OpenTelemetry.Api/Metrics/NoOpCounter.cs rename to src/OpenTelemetry.Api/Metrics/NoOpCounterMetric.cs index 91d48e6dfaa..e208983e4a1 100644 --- a/src/OpenTelemetry.Api/Metrics/NoOpCounter.cs +++ b/src/OpenTelemetry.Api/Metrics/NoOpCounterMetric.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,24 +24,24 @@ namespace OpenTelemetry.Metrics /// A no-op counter instrument. /// /// The type of counter. Only long and double are supported now. - public sealed class NoOpCounter : Counter + public sealed class NoOpCounterMetric : CounterMetric where T : struct { /// /// No op counter instance. /// - public static readonly NoOpCounter Instance = new NoOpCounter(); + public static readonly NoOpCounterMetric Instance = new NoOpCounterMetric(); /// - public override CounterHandle GetHandle(LabelSet labelset) + public override CounterMetricHandle GetHandle(LabelSet labelset) { - return NoOpCounterHandle.Instance; + return NoOpCounterMetricHandle.Instance; } /// - public override CounterHandle GetHandle(IEnumerable> labels) + public override CounterMetricHandle GetHandle(IEnumerable> labels) { - return NoOpCounterHandle.Instance; + return NoOpCounterMetricHandle.Instance; } } } diff --git a/src/OpenTelemetry.Api/Metrics/NoOpCounterHandle.cs b/src/OpenTelemetry.Api/Metrics/NoOpCounterMetricHandle.cs similarity index 82% rename from src/OpenTelemetry.Api/Metrics/NoOpCounterHandle.cs rename to src/OpenTelemetry.Api/Metrics/NoOpCounterMetricHandle.cs index 6e569bad7ea..80adacbb695 100644 --- a/src/OpenTelemetry.Api/Metrics/NoOpCounterHandle.cs +++ b/src/OpenTelemetry.Api/Metrics/NoOpCounterMetricHandle.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,13 +23,13 @@ namespace OpenTelemetry.Metrics /// No-Op handle. /// /// The type of counter. Only long and double are supported now. - public sealed class NoOpCounterHandle : CounterHandle + public sealed class NoOpCounterMetricHandle : CounterMetricHandle where T : struct { /// /// No op counter handle instance. /// - public static readonly NoOpCounterHandle Instance = new NoOpCounterHandle(); + public static readonly NoOpCounterMetricHandle Instance = new NoOpCounterMetricHandle(); /// public override void Add(in SpanContext context, T value) diff --git a/src/OpenTelemetry.Api/Metrics/NoOpMeasure.cs b/src/OpenTelemetry.Api/Metrics/NoOpMeasureMetric.cs similarity index 68% rename from src/OpenTelemetry.Api/Metrics/NoOpMeasure.cs rename to src/OpenTelemetry.Api/Metrics/NoOpMeasureMetric.cs index 11080d48642..7a214819d1c 100644 --- a/src/OpenTelemetry.Api/Metrics/NoOpMeasure.cs +++ b/src/OpenTelemetry.Api/Metrics/NoOpMeasureMetric.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,24 +24,24 @@ namespace OpenTelemetry.Metrics /// No op measure instrument. /// /// The type of counter. Only long and double are supported now. - public sealed class NoOpMeasure : Measure + public sealed class NoOpMeasureMetric : MeasureMetric where T : struct { /// /// No op measure instance. /// - public static readonly NoOpMeasure Instance = new NoOpMeasure(); + public static readonly NoOpMeasureMetric Instance = new NoOpMeasureMetric(); /// - public override MeasureHandle GetHandle(LabelSet labelset) + public override MeasureMetricHandle GetHandle(LabelSet labelset) { - return NoOpMeasureHandle.Instance; + return NoOpMeasureMetricHandle.Instance; } /// - public override MeasureHandle GetHandle(IEnumerable> labels) + public override MeasureMetricHandle GetHandle(IEnumerable> labels) { - return NoOpMeasureHandle.Instance; + return NoOpMeasureMetricHandle.Instance; } } } diff --git a/src/OpenTelemetry.Api/Metrics/NoOpMeasureHandle.cs b/src/OpenTelemetry.Api/Metrics/NoOpMeasureMetricHandle.cs similarity index 82% rename from src/OpenTelemetry.Api/Metrics/NoOpMeasureHandle.cs rename to src/OpenTelemetry.Api/Metrics/NoOpMeasureMetricHandle.cs index b9477a11256..095acd01d1e 100644 --- a/src/OpenTelemetry.Api/Metrics/NoOpMeasureHandle.cs +++ b/src/OpenTelemetry.Api/Metrics/NoOpMeasureMetricHandle.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,13 +23,13 @@ namespace OpenTelemetry.Metrics /// No op measure handle. /// /// The type of Measure. Only long and double are supported now. - public sealed class NoOpMeasureHandle : MeasureHandle + public sealed class NoOpMeasureMetricHandle : MeasureMetricHandle where T : struct { /// /// No op measure handle instance. /// - public static readonly NoOpMeasureHandle Instance = new NoOpMeasureHandle(); + public static readonly NoOpMeasureMetricHandle Instance = new NoOpMeasureMetricHandle(); /// public override void Record(in SpanContext context, T value) diff --git a/src/OpenTelemetry.Api/Metrics/NoOpMeter.cs b/src/OpenTelemetry.Api/Metrics/NoOpMeter.cs index 3b094aa7fa4..eb695ae7721 100644 --- a/src/OpenTelemetry.Api/Metrics/NoOpMeter.cs +++ b/src/OpenTelemetry.Api/Metrics/NoOpMeter.cs @@ -24,34 +24,34 @@ public NoOpMeter() { } - public override Counter CreateDoubleCounter(string name, bool monotonic = true) + public override CounterMetric CreateDoubleCounter(string name, bool monotonic = true) { - return NoOpCounter.Instance; + return NoOpCounterMetric.Instance; } - public override Gauge CreateDoubleGauge(string name, bool monotonic = false) + public override MeasureMetric CreateDoubleMeasure(string name, bool absolute = true) { - return NoOpGauge.Instance; + return NoOpMeasureMetric.Instance; } - public override Measure CreateDoubleMeasure(string name, bool absolute = true) + public override ObserverMetric CreateDoubleObserver(string name, bool monotonic = true) { - return NoOpMeasure.Instance; + return NoOpObserverMetric.Instance; } - public override Counter CreateInt64Counter(string name, bool monotonic = true) + public override CounterMetric CreateInt64Counter(string name, bool monotonic = true) { - return NoOpCounter.Instance; + return NoOpCounterMetric.Instance; } - public override Gauge CreateInt64Gauge(string name, bool monotonic = false) + public override MeasureMetric CreateInt64Measure(string name, bool absolute = true) { - return NoOpGauge.Instance; + return NoOpMeasureMetric.Instance; } - public override Measure CreateInt64Measure(string name, bool absolute = true) + public override ObserverMetric CreateInt64Observer(string name, bool absolute = true) { - return NoOpMeasure.Instance; + return NoOpObserverMetric.Instance; } public override LabelSet GetLabelSet(IEnumerable> labels) diff --git a/src/OpenTelemetry.Api/Metrics/NoOpGauge.cs b/src/OpenTelemetry.Api/Metrics/NoOpObserverMetric.cs similarity index 57% rename from src/OpenTelemetry.Api/Metrics/NoOpGauge.cs rename to src/OpenTelemetry.Api/Metrics/NoOpObserverMetric.cs index 59317f943b1..109495375a8 100644 --- a/src/OpenTelemetry.Api/Metrics/NoOpGauge.cs +++ b/src/OpenTelemetry.Api/Metrics/NoOpObserverMetric.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,27 +21,27 @@ namespace OpenTelemetry.Metrics { /// - /// A no-op gauge instrument. + /// A no-op observer instrument. /// - /// The type of gauge. Only long and double are supported now. - public sealed class NoOpGauge : Gauge + /// The type of observer. Only long and double are supported now. + public sealed class NoOpObserverMetric : ObserverMetric where T : struct { /// - /// No op gauge instance. + /// No op observer instance. /// - public static readonly NoOpGauge Instance = new NoOpGauge(); + public static readonly NoOpObserverMetric Instance = new NoOpObserverMetric(); /// - public override GaugeHandle GetHandle(LabelSet labelset) + public override ObserverMetricHandle GetHandle(LabelSet labelset) { - return NoOpGaugeHandle.Instance; + return NoOpObserverMetricHandle.Instance; } /// - public override GaugeHandle GetHandle(IEnumerable> labels) + public override ObserverMetricHandle GetHandle(IEnumerable> labels) { - return NoOpGaugeHandle.Instance; + return NoOpObserverMetricHandle.Instance; } } } diff --git a/src/OpenTelemetry.Api/Metrics/NoOpGaugeHandle.cs b/src/OpenTelemetry.Api/Metrics/NoOpObserverMetricHandle.cs similarity index 61% rename from src/OpenTelemetry.Api/Metrics/NoOpGaugeHandle.cs rename to src/OpenTelemetry.Api/Metrics/NoOpObserverMetricHandle.cs index fb9a6745fc9..c6a93ae84b6 100644 --- a/src/OpenTelemetry.Api/Metrics/NoOpGaugeHandle.cs +++ b/src/OpenTelemetry.Api/Metrics/NoOpObserverMetricHandle.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,24 +20,24 @@ namespace OpenTelemetry.Metrics { /// - /// No-Op handle. + /// No-Op observer handle. /// - /// The type of gauge. Only long and double are supported now. - public sealed class NoOpGaugeHandle : GaugeHandle + /// The type of observer. Only long and double are supported now. + public sealed class NoOpObserverMetricHandle : ObserverMetricHandle where T : struct { /// - /// No op gauge handle instance. + /// No op observer handle instance. /// - public static readonly NoOpGaugeHandle Instance = new NoOpGaugeHandle(); + public static readonly NoOpObserverMetricHandle Instance = new NoOpObserverMetricHandle(); /// - public override void Set(in SpanContext context, T value) + public override void Observe(in SpanContext context, T value) { } /// - public override void Set(in DistributedContext context, T value) + public override void Observe(in DistributedContext context, T value) { } } diff --git a/src/OpenTelemetry.Api/Metrics/Gauge.cs b/src/OpenTelemetry.Api/Metrics/ObserverMetric.cs similarity index 58% rename from src/OpenTelemetry.Api/Metrics/Gauge.cs rename to src/OpenTelemetry.Api/Metrics/ObserverMetric.cs index 8e192ba71a0..99e25fa2645 100644 --- a/src/OpenTelemetry.Api/Metrics/Gauge.cs +++ b/src/OpenTelemetry.Api/Metrics/ObserverMetric.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,56 +21,56 @@ namespace OpenTelemetry.Metrics { /// - /// Gauge instrument. + /// Observer instrument. /// - /// The type of gauge. Only long and double are supported now. - public abstract class Gauge + /// The type of observer. Only long and double are supported now. + public abstract class ObserverMetric where T : struct { /// - /// Sets the value of the Gauge. + /// Observes a value. /// /// the associated span context. - /// value to which the Gauge should be set. + /// value to record. /// The labelset associated with this value. - public void Set(in SpanContext context, T value, LabelSet labelset) => this.GetHandle(labelset).Set(context, value); + public void Observe(in SpanContext context, T value, LabelSet labelset) => this.GetHandle(labelset).Observe(context, value); /// - /// Sets the Gauge. + /// Observes a value. /// /// the associated span context. - /// value to which the Gauge should be set. + /// value to record. /// The labels or dimensions associated with this value. - public void Set(in SpanContext context, T value, IEnumerable> labels) => this.GetHandle(labels).Set(context, value); + public void Observe(in SpanContext context, T value, IEnumerable> labels) => this.GetHandle(labels).Observe(context, value); /// - /// Sets the value of the Gauge. + /// Observes a value. /// /// the associated distributed context. - /// value to which the Gauge should be set. + /// value to record. /// The labelset associated with this value. - public void Set(in DistributedContext context, T value, LabelSet labelset) => this.GetHandle(labelset).Set(context, value); + public void Observe(in DistributedContext context, T value, LabelSet labelset) => this.GetHandle(labelset).Observe(context, value); /// - /// Sets the Gauge. + /// Observes a value. /// /// the associated distributed context. - /// value to which the Gauge should be set. + /// value to record. /// The labels or dimensions associated with this value. - public void Set(in DistributedContext context, T value, IEnumerable> labels) => this.GetHandle(labels).Set(context, value); + public void Observe(in DistributedContext context, T value, IEnumerable> labels) => this.GetHandle(labels).Observe(context, value); /// /// Gets the handle with given labelset. /// /// The labelset from which handle should be constructed. /// The handle. - public abstract GaugeHandle GetHandle(LabelSet labelset); + public abstract ObserverMetricHandle GetHandle(LabelSet labelset); /// - /// Gets the handle with given labels. + /// Gets the handle with given labelset. /// /// The labels or dimensions associated with this value. /// The handle. - public abstract GaugeHandle GetHandle(IEnumerable> labels); + public abstract ObserverMetricHandle GetHandle(IEnumerable> labels); } } diff --git a/src/OpenTelemetry.Api/Metrics/GaugeHandle.cs b/src/OpenTelemetry.Api/Metrics/ObserverMetricHandle.cs similarity index 57% rename from src/OpenTelemetry.Api/Metrics/GaugeHandle.cs rename to src/OpenTelemetry.Api/Metrics/ObserverMetricHandle.cs index 261d51ff507..b767013ab34 100644 --- a/src/OpenTelemetry.Api/Metrics/GaugeHandle.cs +++ b/src/OpenTelemetry.Api/Metrics/ObserverMetricHandle.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,24 +20,24 @@ namespace OpenTelemetry.Metrics { /// - /// Handle to the metrics gauge with the defined . + /// Handle to the metrics observer with the defined . /// - /// The type of gauge. Only long and double are supported now. - public abstract class GaugeHandle + /// The type of observer. Only long and double are supported now. + public abstract class ObserverMetricHandle where T : struct { /// - /// Sets the value of the guague. + /// Sets the value of the observer handle. /// /// the associated span context. - /// value by which the gauge handle should be set. - public abstract void Set(in SpanContext context, T value); + /// value by which the observer handle should be Recorded. + public abstract void Observe(in SpanContext context, T value); /// - /// Sets the value of the guague handle. + /// Sets the value of the observer handle. /// /// the associated distributed context. - /// value by which the gauge handle should be set. - public abstract void Set(in DistributedContext context, T value); + /// value by which the observer handle should be Recorded. + public abstract void Observe(in DistributedContext context, T value); } } diff --git a/src/OpenTelemetry/Metrics/Aggregators/GaugeAggregator.cs b/src/OpenTelemetry/Metrics/Aggregators/LastValueAggregator.cs similarity index 68% rename from src/OpenTelemetry/Metrics/Aggregators/GaugeAggregator.cs rename to src/OpenTelemetry/Metrics/Aggregators/LastValueAggregator.cs index a2cdee96412..2d4c4d441dd 100644 --- a/src/OpenTelemetry/Metrics/Aggregators/GaugeAggregator.cs +++ b/src/OpenTelemetry/Metrics/Aggregators/LastValueAggregator.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,24 +14,21 @@ // limitations under the License. // -using System; - namespace OpenTelemetry.Metrics.Aggregators { /// - /// Basic aggregator which keeps the last recorded value and timestamp. + /// Simple aggregator that only keeps the last value. /// - /// Type of gauge. - public class GaugeAggregator : Aggregator + /// Type of measure instrument. + public class LastValueAggregator : Aggregator where T : struct { private T value; - private DateTime timestamp; - private Tuple checkpoint; + private T checkpoint; public override void Checkpoint() { - this.checkpoint = new Tuple(this.value, this.timestamp); + this.checkpoint = this.value; } public override void Update(T value) @@ -44,11 +41,9 @@ public override void Update(T value) { this.value = (T)(object)((long)(object)value); } - - this.timestamp = DateTime.UtcNow; } - public Tuple ValueFromLastCheckpoint() + internal T ValueFromLastCheckpoint() { return this.checkpoint; } diff --git a/src/OpenTelemetry/Metrics/CounterHandleSdk.cs b/src/OpenTelemetry/Metrics/CounterMetricHandleSdk.cs similarity index 88% rename from src/OpenTelemetry/Metrics/CounterHandleSdk.cs rename to src/OpenTelemetry/Metrics/CounterMetricHandleSdk.cs index 3445abde1a8..7480de9f989 100644 --- a/src/OpenTelemetry/Metrics/CounterHandleSdk.cs +++ b/src/OpenTelemetry/Metrics/CounterMetricHandleSdk.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,12 +21,12 @@ namespace OpenTelemetry.Metrics { - internal class CounterHandleSdk : CounterHandle + internal class CounterMetricHandleSdk : CounterMetricHandle where T : struct { private readonly CounterSumAggregator sumAggregator = new CounterSumAggregator(); - internal CounterHandleSdk() + internal CounterMetricHandleSdk() { if (typeof(T) != typeof(long) && typeof(T) != typeof(double)) { diff --git a/src/OpenTelemetry/Metrics/CounterSdk.cs b/src/OpenTelemetry/Metrics/CounterMetricSdk.cs similarity index 66% rename from src/OpenTelemetry/Metrics/CounterSdk.cs rename to src/OpenTelemetry/Metrics/CounterMetricSdk.cs index ad4b152474b..937ec0c2bc2 100644 --- a/src/OpenTelemetry/Metrics/CounterSdk.cs +++ b/src/OpenTelemetry/Metrics/CounterMetricSdk.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,13 +20,13 @@ namespace OpenTelemetry.Metrics { - internal class CounterSdk : Counter + internal class CounterMetricSdk : CounterMetric where T : struct - { - private readonly IDictionary> counterHandles = new ConcurrentDictionary>(); + { + private readonly IDictionary> counterHandles = new ConcurrentDictionary>(); private string metricName; - public CounterSdk() + public CounterMetricSdk() { if (typeof(T) != typeof(long) && typeof(T) != typeof(double)) { @@ -34,16 +34,16 @@ public CounterSdk() } } - public CounterSdk(string name) : this() + public CounterMetricSdk(string name) : this() { this.metricName = name; } - public override CounterHandle GetHandle(LabelSet labelset) + public override CounterMetricHandle GetHandle(LabelSet labelset) { if (!this.counterHandles.TryGetValue(labelset, out var handle)) { - handle = new CounterHandleSdk(); + handle = new CounterMetricHandleSdk(); this.counterHandles.Add(labelset, handle); } @@ -51,12 +51,12 @@ public override CounterHandle GetHandle(LabelSet labelset) return handle; } - public override CounterHandle GetHandle(IEnumerable> labels) + public override CounterMetricHandle GetHandle(IEnumerable> labels) { return this.GetHandle(new LabelSetSdk(labels)); } - internal IDictionary> GetAllHandles() + internal IDictionary> GetAllHandles() { return this.counterHandles; } diff --git a/src/OpenTelemetry/Metrics/Export/MetricProcessor.cs b/src/OpenTelemetry/Metrics/Export/MetricProcessor.cs index 9c197b20ba8..d3f1cf95838 100644 --- a/src/OpenTelemetry/Metrics/Export/MetricProcessor.cs +++ b/src/OpenTelemetry/Metrics/Export/MetricProcessor.cs @@ -39,39 +39,39 @@ public abstract class MetricProcessor public abstract void ProcessCounter(string meterName, string metricName, LabelSet labelSet, CounterSumAggregator sumAggregator); /// - /// Process the gauge metric. + /// Process the measure metric. /// /// the name of the meter, used as a namespace for the metric instruments. /// the name of the counter. /// the labelSet associated with counter value. - /// the aggregator from which current value can be obtained. - public abstract void ProcessGauge(string meterName, string metricName, LabelSet labelSet, GaugeAggregator gaugeAggregator); + /// the aggregator from which raw values can be obtained. + public abstract void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator); /// - /// Process the gauge metric. + /// Process the measure metric. /// /// the name of the meter, used as a namespace for the metric instruments. /// the name of the counter. /// the labelSet associated with counter value. - /// the aggregator from which current value can be obtained. - public abstract void ProcessGauge(string meterName, string metricName, LabelSet labelSet, GaugeAggregator gaugeAggregator); + /// the aggregator from which raw values can be obtained. + public abstract void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator); /// - /// Process the gauge metric. + /// Process the observer metric. /// /// the name of the meter, used as a namespace for the metric instruments. - /// the name of the counter. - /// the labelSet associated with counter value. - /// the aggregator from which raw values can be obtained. - public abstract void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator); + /// the name of the observer. + /// the labelSet associated with observer value. + /// the aggregator from which raw values can be obtained. + public abstract void ProcessObserver(string meterName, string metricName, LabelSet labelSet, LastValueAggregator lastValueAggregator); /// - /// Process the gauge metric. + /// Process the observer metric. /// /// the name of the meter, used as a namespace for the metric instruments. - /// the name of the counter. - /// the labelSet associated with counter value. - /// the aggregator from which raw values can be obtained. - public abstract void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator); + /// the name of the observer. + /// the labelSet associated with observer value. + /// the aggregator from which raw values can be obtained. + public abstract void ProcessObserver(string meterName, string metricName, LabelSet labelSet, LastValueAggregator lastValueAggregator); } } diff --git a/src/OpenTelemetry/Metrics/Export/NoOpMetricProcessor.cs b/src/OpenTelemetry/Metrics/Export/NoOpMetricProcessor.cs index f8aaccae81b..16c7c786eec 100644 --- a/src/OpenTelemetry/Metrics/Export/NoOpMetricProcessor.cs +++ b/src/OpenTelemetry/Metrics/Export/NoOpMetricProcessor.cs @@ -28,19 +28,19 @@ public override void ProcessCounter(string meterName, string metricName, LabelSe { } - public override void ProcessGauge(string meterName, string metricName, LabelSet labelSet, GaugeAggregator gaugeAggregator) + public override void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator) { } - public override void ProcessGauge(string meterName, string metricName, LabelSet labelSet, GaugeAggregator gaugeAggregator) + public override void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator) { } - public override void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator) + public override void ProcessObserver(string meterName, string metricName, LabelSet labelSet, LastValueAggregator lastValueAggregator) { } - public override void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator) + public override void ProcessObserver(string meterName, string metricName, LabelSet labelSet, LastValueAggregator lastValueAggregator) { } } diff --git a/src/OpenTelemetry/Metrics/Export/UngroupedBatcher.cs b/src/OpenTelemetry/Metrics/Export/UngroupedBatcher.cs index e4e033f2f07..d3842371324 100644 --- a/src/OpenTelemetry/Metrics/Export/UngroupedBatcher.cs +++ b/src/OpenTelemetry/Metrics/Export/UngroupedBatcher.cs @@ -29,7 +29,7 @@ namespace OpenTelemetry.Metrics.Export /// public class UngroupedBatcher : MetricProcessor { - private readonly MetricExporter exporter; + private readonly MetricExporter exporter; private readonly Task worker; private readonly TimeSpan aggregationInterval; private CancellationTokenSource cts; @@ -70,29 +70,29 @@ public override void ProcessCounter(string meterName, string metricName, LabelSe throw new NotImplementedException(); } - public override void ProcessGauge(string meterName, string metricName, LabelSet labelSet, GaugeAggregator gaugeAggregator) + public override void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator) { throw new NotImplementedException(); } - public override void ProcessGauge(string meterName, string metricName, LabelSet labelSet, GaugeAggregator gaugeAggregator) + public override void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator) { throw new NotImplementedException(); } - public override void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator) + public override void ProcessObserver(string meterName, string metricName, LabelSet labelSet, LastValueAggregator lastValueAggregator) { throw new NotImplementedException(); } - public override void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator) + public override void ProcessObserver(string meterName, string metricName, LabelSet labelSet, LastValueAggregator lastValueAggregator) { throw new NotImplementedException(); } private async Task Worker(CancellationToken cancellationToken) { - try + try { await Task.Delay(this.aggregationInterval, cancellationToken).ConfigureAwait(false); while (!cancellationToken.IsCancellationRequested) diff --git a/src/OpenTelemetry/Metrics/MeasureHandleSdk.cs b/src/OpenTelemetry/Metrics/MeasureMetricHandleSdk.cs similarity index 88% rename from src/OpenTelemetry/Metrics/MeasureHandleSdk.cs rename to src/OpenTelemetry/Metrics/MeasureMetricHandleSdk.cs index ff225fb881c..5ccef7983b0 100644 --- a/src/OpenTelemetry/Metrics/MeasureHandleSdk.cs +++ b/src/OpenTelemetry/Metrics/MeasureMetricHandleSdk.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,12 +21,12 @@ namespace OpenTelemetry.Metrics { - internal class MeasureHandleSdk : MeasureHandle + internal class MeasureMetricHandleSdk : MeasureMetricHandle where T : struct { private readonly MeasureExactAggregator measureExactAggregator = new MeasureExactAggregator(); - internal MeasureHandleSdk() + internal MeasureMetricHandleSdk() { if (typeof(T) != typeof(long) && typeof(T) != typeof(double)) { diff --git a/src/OpenTelemetry/Metrics/MeasureSdk.cs b/src/OpenTelemetry/Metrics/MeasureMetricSdk.cs similarity index 66% rename from src/OpenTelemetry/Metrics/MeasureSdk.cs rename to src/OpenTelemetry/Metrics/MeasureMetricSdk.cs index ea296a313ec..a0c0e8573a1 100644 --- a/src/OpenTelemetry/Metrics/MeasureSdk.cs +++ b/src/OpenTelemetry/Metrics/MeasureMetricSdk.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,13 +20,13 @@ namespace OpenTelemetry.Metrics { - internal class MeasureSdk : Measure + internal class MeasureMetricSdk : MeasureMetric where T : struct - { - private readonly IDictionary> measureHandles = new ConcurrentDictionary>(); + { + private readonly IDictionary> measureHandles = new ConcurrentDictionary>(); private string metricName; - public MeasureSdk() + public MeasureMetricSdk() { if (typeof(T) != typeof(long) && typeof(T) != typeof(double)) { @@ -34,16 +34,16 @@ public MeasureSdk() } } - public MeasureSdk(string name) : this() + public MeasureMetricSdk(string name) : this() { this.metricName = name; } - public override MeasureHandle GetHandle(LabelSet labelset) + public override MeasureMetricHandle GetHandle(LabelSet labelset) { if (!this.measureHandles.TryGetValue(labelset, out var handle)) { - handle = new MeasureHandleSdk(); + handle = new MeasureMetricHandleSdk(); this.measureHandles.Add(labelset, handle); } @@ -51,12 +51,12 @@ public override MeasureHandle GetHandle(LabelSet labelset) return handle; } - public override MeasureHandle GetHandle(IEnumerable> labels) + public override MeasureMetricHandle GetHandle(IEnumerable> labels) { return this.GetHandle(new LabelSetSdk(labels)); } - internal IDictionary> GetAllHandles() + internal IDictionary> GetAllHandles() { return this.measureHandles; } diff --git a/src/OpenTelemetry/Metrics/MeterSdk.cs b/src/OpenTelemetry/Metrics/MeterSdk.cs index 50ad38e27c8..1f6ba7d14ff 100644 --- a/src/OpenTelemetry/Metrics/MeterSdk.cs +++ b/src/OpenTelemetry/Metrics/MeterSdk.cs @@ -25,18 +25,18 @@ public class MeterSdk : Meter { private readonly string meterName; private readonly MetricProcessor metricProcessor; - private readonly IDictionary> longCounters = new ConcurrentDictionary>(); - private readonly IDictionary> doubleCounters = new ConcurrentDictionary>(); - private readonly IDictionary> longGauges = new ConcurrentDictionary>(); - private readonly IDictionary> doubleGauges = new ConcurrentDictionary>(); - private readonly IDictionary> longMeasures = new ConcurrentDictionary>(); - private readonly IDictionary> doubleMeasures = new ConcurrentDictionary>(); + private readonly IDictionary> longCounters = new ConcurrentDictionary>(); + private readonly IDictionary> doubleCounters = new ConcurrentDictionary>(); + private readonly IDictionary> longMeasures = new ConcurrentDictionary>(); + private readonly IDictionary> doubleMeasures = new ConcurrentDictionary>(); + private readonly IDictionary> longObservers = new ConcurrentDictionary>(); + private readonly IDictionary> doubleObservers = new ConcurrentDictionary>(); private readonly object collectLock = new object(); internal MeterSdk(string meterName, MetricProcessor metricProcessor) { this.meterName = meterName; - this.metricProcessor = metricProcessor; + this.metricProcessor = metricProcessor; } public override LabelSet GetLabelSet(IEnumerable> labels) @@ -76,65 +76,65 @@ public void Collect() } } - foreach (var longGauge in this.longGauges) + foreach (var longMeasure in this.longMeasures) { - var metricName = longGauge.Key; - var gaugeInstrument = longGauge.Value; - foreach (var handle in gaugeInstrument.GetAllHandles()) + var metricName = longMeasure.Key; + var measureInstrument = longMeasure.Value; + foreach (var handle in measureInstrument.GetAllHandles()) { var labelSet = handle.Key; var aggregator = handle.Value.GetAggregator(); aggregator.Checkpoint(); - this.metricProcessor.ProcessGauge(this.meterName, metricName, labelSet, aggregator); + this.metricProcessor.ProcessMeasure(this.meterName, metricName, labelSet, aggregator); } } - foreach (var doubleGauge in this.doubleGauges) + foreach (var doubleMeasure in this.doubleMeasures) { - var metricName = doubleGauge.Key; - var gaugeInstrument = doubleGauge.Value; - foreach (var handle in gaugeInstrument.GetAllHandles()) + var metricName = doubleMeasure.Key; + var measureInstrument = doubleMeasure.Value; + foreach (var handle in measureInstrument.GetAllHandles()) { var labelSet = handle.Key; var aggregator = handle.Value.GetAggregator(); aggregator.Checkpoint(); - this.metricProcessor.ProcessGauge(this.meterName, metricName, labelSet, aggregator); + this.metricProcessor.ProcessMeasure(this.meterName, metricName, labelSet, aggregator); } } - foreach (var longMeasure in this.longMeasures) + foreach (var doubleObserver in this.doubleObservers) { - var metricName = longMeasure.Key; - var measureInstrument = longMeasure.Value; + var metricName = doubleObserver.Key; + var measureInstrument = doubleObserver.Value; foreach (var handle in measureInstrument.GetAllHandles()) { var labelSet = handle.Key; var aggregator = handle.Value.GetAggregator(); aggregator.Checkpoint(); - this.metricProcessor.ProcessMeasure(this.meterName, metricName, labelSet, aggregator); + this.metricProcessor.ProcessObserver(this.meterName, metricName, labelSet, aggregator); } } - foreach (var doubleMeasure in this.doubleMeasures) + foreach (var longObserver in this.longObservers) { - var metricName = doubleMeasure.Key; - var measureInstrument = doubleMeasure.Value; + var metricName = longObserver.Key; + var measureInstrument = longObserver.Value; foreach (var handle in measureInstrument.GetAllHandles()) { var labelSet = handle.Key; var aggregator = handle.Value.GetAggregator(); aggregator.Checkpoint(); - this.metricProcessor.ProcessMeasure(this.meterName, metricName, labelSet, aggregator); + this.metricProcessor.ProcessObserver(this.meterName, metricName, labelSet, aggregator); } } } } - public override Counter CreateInt64Counter(string name, bool monotonic = true) + public override CounterMetric CreateInt64Counter(string name, bool monotonic = true) { if (!this.longCounters.TryGetValue(name, out var counter)) { - counter = new CounterSdk(name); + counter = new CounterMetricSdk(name); this.longCounters.Add(name, counter); } @@ -142,63 +142,65 @@ public override Counter CreateInt64Counter(string name, bool monotonic = t return counter; } - public override Counter CreateDoubleCounter(string name, bool monotonic = true) + public override CounterMetric CreateDoubleCounter(string name, bool monotonic = true) { if (!this.doubleCounters.TryGetValue(name, out var counter)) { - counter = new CounterSdk(name); + counter = new CounterMetricSdk(name); this.doubleCounters.Add(name, counter); } return counter; } - public override Gauge CreateInt64Gauge(string name, bool monotonic = true) + public override MeasureMetric CreateDoubleMeasure(string name, bool absolute = true) { - if (!this.longGauges.TryGetValue(name, out var gauge)) + if (!this.doubleMeasures.TryGetValue(name, out var measure)) { - gauge = new GaugeSDK(name); + measure = new MeasureMetricSdk(name); - this.longGauges.Add(name, gauge); + this.doubleMeasures.Add(name, measure); } - return gauge; + return measure; } - public override Gauge CreateDoubleGauge(string name, bool monotonic = true) + public override MeasureMetric CreateInt64Measure(string name, bool absolute = true) { - if (!this.doubleGauges.TryGetValue(name, out var gauge)) + if (!this.longMeasures.TryGetValue(name, out var measure)) { - gauge = new GaugeSDK(name); + measure = new MeasureMetricSdk(name); - this.doubleGauges.Add(name, gauge); + this.longMeasures.Add(name, measure); } - return gauge; + return measure; } - public override Measure CreateDoubleMeasure(string name, bool absolute = true) + /// + public override ObserverMetric CreateInt64Observer(string name, bool absolute = true) { - if (!this.doubleMeasures.TryGetValue(name, out var measure)) + if (!this.longObservers.TryGetValue(name, out var observer)) { - measure = new MeasureSdk(name); + observer = new ObserverMetricSdk(name); - this.doubleMeasures.Add(name, measure); + this.longObservers.Add(name, observer); } - return measure; + return observer; } - public override Measure CreateInt64Measure(string name, bool absolute = true) + /// + public override ObserverMetric CreateDoubleObserver(string name, bool absolute = true) { - if (!this.longMeasures.TryGetValue(name, out var measure)) + if (!this.doubleObservers.TryGetValue(name, out var observer)) { - measure = new MeasureSdk(name); + observer = new ObserverMetricSdk(name); - this.longMeasures.Add(name, measure); + this.doubleObservers.Add(name, observer); } - return measure; + return observer; } } } diff --git a/src/OpenTelemetry/Metrics/GaugeHandleSdk.cs b/src/OpenTelemetry/Metrics/ObserverMetricHandleSdk.cs similarity index 62% rename from src/OpenTelemetry/Metrics/GaugeHandleSdk.cs rename to src/OpenTelemetry/Metrics/ObserverMetricHandleSdk.cs index 7daacfb87db..58ab1d3ab64 100644 --- a/src/OpenTelemetry/Metrics/GaugeHandleSdk.cs +++ b/src/OpenTelemetry/Metrics/ObserverMetricHandleSdk.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,12 +21,12 @@ namespace OpenTelemetry.Metrics { - internal class GaugeHandleSdk : GaugeHandle + internal class ObserverMetricHandleSdk : ObserverMetricHandle where T : struct { - private readonly GaugeAggregator gaugeAggregator = new GaugeAggregator(); + private readonly LastValueAggregator aggregator = new LastValueAggregator(); - internal GaugeHandleSdk() + internal ObserverMetricHandleSdk() { if (typeof(T) != typeof(long) && typeof(T) != typeof(double)) { @@ -34,19 +34,19 @@ internal GaugeHandleSdk() } } - public override void Set(in SpanContext context, T value) + public override void Observe(in SpanContext context, T value) { - this.gaugeAggregator.Update(value); + this.aggregator.Update(value); } - public override void Set(in DistributedContext context, T value) + public override void Observe(in DistributedContext context, T value) { - this.gaugeAggregator.Update(value); + this.aggregator.Update(value); } - internal GaugeAggregator GetAggregator() + internal LastValueAggregator GetAggregator() { - return this.gaugeAggregator; + return this.aggregator; } } } diff --git a/src/OpenTelemetry/Metrics/GaugeSdk.cs b/src/OpenTelemetry/Metrics/ObserverMetricSdk.cs similarity index 57% rename from src/OpenTelemetry/Metrics/GaugeSdk.cs rename to src/OpenTelemetry/Metrics/ObserverMetricSdk.cs index b358a4d3126..6d32bff0f96 100644 --- a/src/OpenTelemetry/Metrics/GaugeSdk.cs +++ b/src/OpenTelemetry/Metrics/ObserverMetricSdk.cs @@ -1,4 +1,4 @@ -// +// // Copyright 2018, OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,13 +20,13 @@ namespace OpenTelemetry.Metrics { - internal class GaugeSDK : Gauge + internal class ObserverMetricSdk : ObserverMetric where T : struct - { - private readonly IDictionary> gaugeHandles = new ConcurrentDictionary>(); + { + private readonly IDictionary> observerHandles = new ConcurrentDictionary>(); private string metricName; - public GaugeSDK() + public ObserverMetricSdk() { if (typeof(T) != typeof(long) && typeof(T) != typeof(double)) { @@ -34,31 +34,31 @@ public GaugeSDK() } } - public GaugeSDK(string name) : this() + public ObserverMetricSdk(string name) : this() { this.metricName = name; } - public override GaugeHandle GetHandle(LabelSet labelset) + public override ObserverMetricHandle GetHandle(LabelSet labelset) { - if (!this.gaugeHandles.TryGetValue(labelset, out var handle)) + if (!this.observerHandles.TryGetValue(labelset, out var handle)) { - handle = new GaugeHandleSdk(); + handle = new ObserverMetricHandleSdk(); - this.gaugeHandles.Add(labelset, handle); + this.observerHandles.Add(labelset, handle); } return handle; } - public override GaugeHandle GetHandle(IEnumerable> labels) + public override ObserverMetricHandle GetHandle(IEnumerable> labels) { return this.GetHandle(new LabelSetSdk(labels)); } - internal IDictionary> GetAllHandles() + internal IDictionary> GetAllHandles() { - return this.gaugeHandles; + return this.observerHandles; } } } diff --git a/test/OpenTelemetry.Tests/Impl/Metrics/MetricsTest.cs b/test/OpenTelemetry.Tests/Impl/Metrics/MetricsTest.cs index 20c668b7560..71c0512b51f 100644 --- a/test/OpenTelemetry.Tests/Impl/Metrics/MetricsTest.cs +++ b/test/OpenTelemetry.Tests/Impl/Metrics/MetricsTest.cs @@ -13,9 +13,10 @@ // See the License for the specific language governing permissions and // limitations under the License. // + +using System.Linq; using System.Collections.Generic; using OpenTelemetry.Metrics.Configuration; -using OpenTelemetry.Metrics.Export; using OpenTelemetry.Trace; using Xunit; @@ -23,13 +24,13 @@ namespace OpenTelemetry.Metrics.Test { public class MetricsTest { - [Fact(Skip = "TODO: Make robust tests. These are just basic tests to see metric in action.")] + [Fact] public void CounterSendsAggregateToRegisteredProcessor() { var testProcessor = new TestMetricProcessor(); var meter = MeterFactory.Create(testProcessor).GetMeter("library1") as MeterSdk; var testCounter = meter.CreateInt64Counter("testCounter"); - + var labels1 = new List>(); labels1.Add(new KeyValuePair("dim1", "value1")); @@ -45,22 +46,21 @@ public void CounterSendsAggregateToRegisteredProcessor() meter.Collect(); Assert.Equal(2, testProcessor.counters.Count); - Assert.Equal("testCounter", testProcessor.counters[1].Item1); - Assert.Equal("testCounter", testProcessor.counters[0].Item1); + Assert.Equal(2, testProcessor.counters.Count(kvp => kvp.Item1 == "testCounter")); - Assert.Equal(meter.GetLabelSet(labels1), testProcessor.counters[1].Item2); - Assert.Equal(meter.GetLabelSet(labels2), testProcessor.counters[0].Item2); + Assert.Single(testProcessor.counters.Where(kvp => kvp.Item2.Equals(meter.GetLabelSet(labels1)))); + Assert.Single(testProcessor.counters.Where(kvp => kvp.Item2.Equals(meter.GetLabelSet(labels2)))); - Assert.Equal(110, testProcessor.counters[1].Item3); - Assert.Equal(210, testProcessor.counters[0].Item3); + Assert.Single(testProcessor.counters.Where(kvp => kvp.Item3 == 110)); + Assert.Single(testProcessor.counters.Where(kvp => kvp.Item3 == 210)); } - [Fact(Skip = "TODO: Make robust tests. These are just basic tests to see metric in action.")] - public void GaugeSendsAggregateToRegisteredProcessor() + [Fact] + public void MeasureSendsAggregateToRegisteredProcessor() { var testProcessor = new TestMetricProcessor(); var meter = MeterFactory.Create(testProcessor).GetMeter("library1") as MeterSdk; - var testGauge = meter.CreateInt64Gauge("testGauge"); + var testMeasure = meter.CreateInt64Measure("testMeasure"); var labels1 = new List>(); labels1.Add(new KeyValuePair("dim1", "value1")); @@ -69,31 +69,29 @@ public void GaugeSendsAggregateToRegisteredProcessor() labels2.Add(new KeyValuePair("dim1", "value2")); var context = default(SpanContext); - testGauge.Set(context, 100, meter.GetLabelSet(labels1)); - testGauge.Set(context, 10, meter.GetLabelSet(labels1)); - testGauge.Set(context, 200, meter.GetLabelSet(labels2)); - testGauge.Set(context, 20, meter.GetLabelSet(labels2)); + testMeasure.Record(context, 100, meter.GetLabelSet(labels1)); + testMeasure.Record(context, 10, meter.GetLabelSet(labels1)); + testMeasure.Record(context, 200, meter.GetLabelSet(labels2)); + testMeasure.Record(context, 20, meter.GetLabelSet(labels2)); meter.Collect(); - Assert.Equal(2, testProcessor.gauges.Count); - Assert.Equal("testGauge", testProcessor.gauges[1].Item1); - Assert.Equal("testGauge", testProcessor.gauges[0].Item1); + Assert.Equal(2, testProcessor.measures.Count); + Assert.Equal(2, testProcessor.measures.Count(kvp => kvp.Item1 == "testMeasure")); - Assert.Equal(meter.GetLabelSet(labels1), testProcessor.gauges[1].Item2); - Assert.Equal(meter.GetLabelSet(labels2), testProcessor.gauges[0].Item2); + Assert.Single(testProcessor.measures.Where(kvp => kvp.Item2.Equals(meter.GetLabelSet(labels1)))); + Assert.Single(testProcessor.measures.Where(kvp => kvp.Item2.Equals(meter.GetLabelSet(labels2)))); - Assert.Equal(10, testProcessor.gauges[1].Item3.Item1); - Assert.Equal(20, testProcessor.gauges[0].Item3.Item1); + Assert.Single(testProcessor.measures.Where(kvp => kvp.Item3.Contains(100) && kvp.Item3.Contains(10))); + Assert.Single(testProcessor.measures.Where(kvp => kvp.Item3.Contains(200) && kvp.Item3.Contains(20))); } - - [Fact(Skip = "TODO: Make robust tests. These are just basic tests to see metric in action.")] - public void MeasureSendsAggregateToRegisteredProcessor() + [Fact] + public void ObserverSendsAggregateToRegisteredProcessor() { var testProcessor = new TestMetricProcessor(); var meter = MeterFactory.Create(testProcessor).GetMeter("library1") as MeterSdk; - var testMeasure = meter.CreateInt64Measure("testMeasure"); + var testObserver = meter.CreateInt64Observer("testObserver"); var labels1 = new List>(); labels1.Add(new KeyValuePair("dim1", "value1")); @@ -102,26 +100,21 @@ public void MeasureSendsAggregateToRegisteredProcessor() labels2.Add(new KeyValuePair("dim1", "value2")); var context = default(SpanContext); - testMeasure.Record(context, 100, meter.GetLabelSet(labels1)); - testMeasure.Record(context, 10, meter.GetLabelSet(labels1)); - testMeasure.Record(context, 200, meter.GetLabelSet(labels2)); - testMeasure.Record(context, 20, meter.GetLabelSet(labels2)); + testObserver.Observe(context, 100, meter.GetLabelSet(labels1)); + testObserver.Observe(context, 10, meter.GetLabelSet(labels1)); + testObserver.Observe(context, 200, meter.GetLabelSet(labels2)); + testObserver.Observe(context, 20, meter.GetLabelSet(labels2)); meter.Collect(); - Assert.Equal(2, testProcessor.measures.Count); - Assert.Equal("testMeasure", testProcessor.measures[1].Item1); - Assert.Equal("testMeasure", testProcessor.measures[0].Item1); - - Assert.Equal(meter.GetLabelSet(labels1), testProcessor.measures[1].Item2); - Assert.Equal(meter.GetLabelSet(labels2), testProcessor.measures[0].Item2); - - Assert.Contains(100, testProcessor.measures[1].Item3); - Assert.Contains(10, testProcessor.measures[1].Item3); + Assert.Equal(2, testProcessor.observations.Count); + Assert.Equal(2, testProcessor.observations.Count(kvp => kvp.Item1 == "testObserver")); + Assert.Single(testProcessor.observations.Where(kvp => kvp.Item2.Equals(meter.GetLabelSet(labels1)))); + Assert.Single(testProcessor.observations.Where(kvp => kvp.Item2.Equals(meter.GetLabelSet(labels2)))); - Assert.Contains(200, testProcessor.measures[0].Item3); - Assert.Contains(20, testProcessor.measures[0].Item3); + Assert.Single(testProcessor.observations.Where(kvp => kvp.Item3 == 10)); + Assert.Single(testProcessor.observations.Where(kvp => kvp.Item3 == 20)); } } } diff --git a/test/OpenTelemetry.Tests/Impl/Metrics/TestMetricProcessor.cs b/test/OpenTelemetry.Tests/Impl/Metrics/TestMetricProcessor.cs index 497c9c3997b..5e86d27f996 100644 --- a/test/OpenTelemetry.Tests/Impl/Metrics/TestMetricProcessor.cs +++ b/test/OpenTelemetry.Tests/Impl/Metrics/TestMetricProcessor.cs @@ -24,8 +24,8 @@ namespace OpenTelemetry.Metrics.Test internal class TestMetricProcessor : MetricProcessor { public List> counters = new List>(); - public List>> gauges = new List>>(); public List>> measures = new List>>(); + public List> observations = new List>(); public override void ProcessCounter(string meterName, string metricName, LabelSet labelSet, CounterSumAggregator sumAggregator) { @@ -36,21 +36,21 @@ public override void ProcessCounter(string meterName, string metricName, LabelSe { } - public override void ProcessGauge(string meterName, string metricName, LabelSet labelSet, GaugeAggregator gaugeAggregator) + public override void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator) { - gauges.Add(new Tuple>(metricName, labelSet, gaugeAggregator.ValueFromLastCheckpoint())); + measures.Add(new Tuple>(metricName, labelSet, measureAggregator.ValueFromLastCheckpoint())); } - public override void ProcessGauge(string meterName, string metricName, LabelSet labelSet, GaugeAggregator gaugeAggregator) + public override void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator) { } - public override void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator) + public override void ProcessObserver(string meterName, string metricName, LabelSet labelSet, LastValueAggregator lastValueAggregator) { - measures.Add(new Tuple>(metricName, labelSet, measureAggregator.ValueFromLastCheckpoint())); + observations.Add(new Tuple(metricName, labelSet, lastValueAggregator.ValueFromLastCheckpoint())); } - public override void ProcessMeasure(string meterName, string metricName, LabelSet labelSet, MeasureExactAggregator measureAggregator) + public override void ProcessObserver(string meterName, string metricName, LabelSet labelSet, LastValueAggregator lastValueAggregator) { } } diff --git a/test/OpenTelemetry.Tests/Impl/Trace/Config/MeterFactoryBaseTests.cs b/test/OpenTelemetry.Tests/Impl/Trace/Config/MeterFactoryBaseTests.cs index a6d0a8bd2d8..61567749413 100644 --- a/test/OpenTelemetry.Tests/Impl/Trace/Config/MeterFactoryBaseTests.cs +++ b/test/OpenTelemetry.Tests/Impl/Trace/Config/MeterFactoryBaseTests.cs @@ -36,12 +36,12 @@ public void MeterFactoryBase_Default() Assert.Same(defaultMeter, namedMeter); var counter = defaultMeter.CreateDoubleCounter("somename"); - Assert.IsType>(counter); + Assert.IsType>(counter); var labels1 = new List>(); labels1.Add(new KeyValuePair("dim1", "value1")); var counterHandle = counter.GetHandle(labels1); - Assert.IsType>(counterHandle); + Assert.IsType>(counterHandle); } } }