diff --git a/src/OpenTelemetry.Api/DistributedContext/DistributedContextEntry.cs b/src/OpenTelemetry.Api/DistributedContext/DistributedContextEntry.cs index 02a90a86889..b62b4a73843 100644 --- a/src/OpenTelemetry.Api/DistributedContext/DistributedContextEntry.cs +++ b/src/OpenTelemetry.Api/DistributedContext/DistributedContextEntry.cs @@ -29,7 +29,7 @@ public sealed class DistributedContextEntry /// Key name for the entry. /// Value associated with the key name. public DistributedContextEntry(string key, string value) - : this(key, value, new EntryMetadata(EntryMetadata.NoPropagation)) + : this(key, value, EntryMetadata.NoPropagationEntry) { } diff --git a/src/OpenTelemetry.Api/DistributedContext/EntryMetadata.cs b/src/OpenTelemetry.Api/DistributedContext/EntryMetadata.cs index 930a1844d1d..6f50754c425 100644 --- a/src/OpenTelemetry.Api/DistributedContext/EntryMetadata.cs +++ b/src/OpenTelemetry.Api/DistributedContext/EntryMetadata.cs @@ -22,27 +22,34 @@ namespace OpenTelemetry.Context public readonly struct EntryMetadata { /// - /// TTL indicating in-process only propagation of an entry. + /// TimeToLive (TTL) indicating in-process only propagation of an entry. /// public const int NoPropagation = 0; /// - /// TTL indicating unlimited propagation of an entry. + /// TimeToLive (TTL) indicating unlimited propagation of an entry. /// public const int UnlimitedPropagation = -1; /// /// Initializes a new instance of the struct. /// - /// TTL for the distributed context entry. - public EntryMetadata(int entryTTL) - { - this.EntryTTL = EntryMetadata.NoPropagation; - } + /// TTL for the distributed context entry. + private EntryMetadata(int timeToLive) => this.TimeToLive = timeToLive; /// - /// Gets the EntryTTL is either NO_PROPAGATION (0) or UNLIMITED_PROPAGATION (-1). + /// Gets a new instance of the struct with NoPropagation value. /// - public int EntryTTL { get; } + public static EntryMetadata NoPropagationEntry => new EntryMetadata(NoPropagation); + + /// + /// Gets a new instance of the struct with UnlimitedPropagation value. + /// + public static EntryMetadata UnlimitedPropagationEntry => new EntryMetadata(UnlimitedPropagation); + + /// + /// Gets the TimeToLive which is either NO_PROPAGATION (0) or UNLIMITED_PROPAGATION (-1). + /// + public int TimeToLive { get; } } } diff --git a/src/OpenTelemetry.Api/Metrics/Meter.cs b/src/OpenTelemetry.Api/Metrics/Meter.cs index 117eb4938f2..fbed56e1da0 100644 --- a/src/OpenTelemetry.Api/Metrics/Meter.cs +++ b/src/OpenTelemetry.Api/Metrics/Meter.cs @@ -24,52 +24,52 @@ namespace OpenTelemetry.Metrics public abstract class Meter { /// - /// Creates a counter for long with given name. + /// Creates Int64 counter with given name. /// /// The name of the counter. /// indicates if only positive values are expected. /// The counter instance. - public abstract Counter CreateLongCounter(string name, bool monotonic = true); + public Counter CreateInt64Counter(string name, bool monotonic = true) => this.CreateCounter(name, monotonic); /// - /// Creates a counter for double with given name. + /// Creates double counter with given name. /// /// indicates if only positive values are expected. /// The name of the counter. /// The counter instance. - public abstract Counter CreateDoubleCounter(string name, bool monotonic = true); + public Counter CreateDoubleCounter(string name, bool monotonic = true) => this.CreateCounter(name, monotonic); /// - /// Creates a Gauge for long with given name. + /// Creates Int64 Gauge with given name. /// /// The name of the counter. /// indicates if only positive values are expected. /// The Gauge instance. - public abstract Gauge CreateLongGauge(string name, bool monotonic = false); + public Gauge CreateInt64Gauge(string name, bool monotonic = false) => this.CreateGauge(name, monotonic); /// - /// Creates a Gauge for long 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); - - /// - /// Creates a measure for long with given name. + /// Creates Int64 Measure with given name. /// /// The name of the measure. /// indicates if only positive values are expected. /// The measure instance. - public abstract Measure CreateLongMeasure(string name, bool absolute = true); + public Measure CreateInt64Measure(string name, bool absolute = true) => this.CreateMeasure(name, absolute); /// - /// Creates a measure for long with given name. + /// Creates double Measure with given name. /// /// 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 Measure CreateDoubleMeasure(string name, bool absolute = true) => this.CreateMeasure(name, absolute); + + /// + /// Creates double Gauge with given name. + /// + /// The name of the counter. + /// indicates if only positive values are expected. + /// The Gauge instance. + public Gauge CreateDoubleGauge(string name, bool monotonic = false) => this.CreateGauge(name, monotonic); /// /// Constructs or retrieves the from the given label key-value pairs. @@ -77,5 +77,35 @@ public abstract class Meter /// Label key value pairs. /// The with given label key value pairs. public abstract LabelSet GetLabelSet(IEnumerable> labels); + + /// + /// Creates double or Int64 counter with given name. + /// + /// indicates if only positive values are expected. + /// The name of the counter. + /// The element type of the counter. Should be either long or double. + /// The counter instance. + protected abstract Counter CreateCounter(string name, bool monotonic = true) + where T : struct; + + /// + /// Creates double or Int64 Gauge with given name. + /// + /// The name of the counter. + /// indicates if only positive values are expected. + /// The element type of the Gauge. Should be either long or double. + /// The Gauge instance. + protected abstract Gauge CreateGauge(string name, bool monotonic = false) + where T : struct; + + /// + /// Creates double or Int64 Measure with given name. + /// + /// The name of the measure. + /// indicates if only positive values are expected. + /// The element type of the Measure. Should be either long or double. + /// The measure instance. + protected abstract Measure CreateMeasure(string name, bool absolute = true) + where T : struct; } } diff --git a/src/OpenTelemetry.Api/Metrics/NoOpMeter.cs b/src/OpenTelemetry.Api/Metrics/NoOpMeter.cs index 591c3b0fb20..3f85dbbd836 100644 --- a/src/OpenTelemetry.Api/Metrics/NoOpMeter.cs +++ b/src/OpenTelemetry.Api/Metrics/NoOpMeter.cs @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // +using System; using System.Collections.Generic; namespace OpenTelemetry.Metrics @@ -23,42 +24,41 @@ public NoOpMeter() { } - public override Counter CreateDoubleCounter(string name, bool monotonic = true) - { - // return no op - throw new System.NotImplementedException(); - } - - public override Gauge CreateDoubleGauge(string name, bool monotonic = false) + public override LabelSet GetLabelSet(IEnumerable> labels) { // return no op throw new System.NotImplementedException(); } - public override Measure CreateDoubleMeasure(string name, bool absolute = true) + protected override Counter CreateCounter(string name, bool monotonic = true) { - throw new System.NotImplementedException(); - } + if (typeof(T) != typeof(long) || typeof(T) != typeof(double)) + { + throw new InvalidOperationException(); + } - public override Counter CreateLongCounter(string name, bool monotonic = true) - { // return no op throw new System.NotImplementedException(); } - public override Gauge CreateLongGauge(string name, bool monotonic = false) + protected override Gauge CreateGauge(string name, bool monotonic = true) { + if (typeof(T) != typeof(long) || typeof(T) != typeof(double)) + { + throw new InvalidOperationException(); + } + // return no op throw new System.NotImplementedException(); } - public override Measure CreateLongMeasure(string name, bool absolute = true) + protected override Measure CreateMeasure(string name, bool monotonic = true) { - throw new System.NotImplementedException(); - } + if (typeof(T) != typeof(long) || typeof(T) != typeof(double)) + { + throw new InvalidOperationException(); + } - public override LabelSet GetLabelSet(IEnumerable> labels) - { // return no op throw new System.NotImplementedException(); }