diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs index 10763fefd1af4b..8a769b932817ee 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs @@ -437,6 +437,7 @@ public sealed class InstrumentAdvice where T : struct public Measurement(T value, System.Collections.Generic.IEnumerable>? tags) { throw null; } public Measurement(T value, params System.Collections.Generic.KeyValuePair[]? tags) { throw null; } public Measurement(T value, params System.ReadOnlySpan> tags) { throw null; } + public Measurement(T value, in System.Diagnostics.TagList tags) { throw null; } public ReadOnlySpan> Tags { get { throw null; } } public T Value { get { throw null; } } } diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Measurement.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Measurement.cs index b86b88871ffe5c..f446960d647739 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Measurement.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Measurement.cs @@ -8,17 +8,17 @@ namespace System.Diagnostics.Metrics { /// - /// Measurement stores one observed metrics value and its associated tags. This type is used by Observable instruments' Observe() method when reporting current measurements. - /// with the associated tags. + /// stores one observed value and its associated tags for a metric. + /// Observable instruments use this type when reporting current measurements from their implementation. /// public readonly struct Measurement where T : struct { private readonly KeyValuePair[] _tags; /// - /// Initializes a new instance of the Measurement using the value and the list of tags. + /// Initializes a new instance of with the provided . /// - /// The measurement value. + /// The value of the measurement. public Measurement(T value) { _tags = Instrument.EmptyTags; @@ -26,10 +26,10 @@ public Measurement(T value) } /// - /// Initializes a new instance of the Measurement using the value and the list of tags. + /// Initializes a new instance of Measurement with the provided and zero or more associated . /// - /// The measurement value. - /// The measurement associated tags list. + /// The value of the measurement. + /// The tags associated with the measurement. public Measurement(T value, IEnumerable>? tags) { _tags = ToArray(tags); @@ -37,10 +37,10 @@ public Measurement(T value, IEnumerable>? tags) } /// - /// Initializes a new instance of the Measurement using the value and the list of tags. + /// Initializes a new instance of Measurement with the provided and zero or more associated . /// - /// The measurement value. - /// The measurement associated tags list. + /// The value of the measurement. + /// The tags associated with the measurement. public Measurement(T value, params KeyValuePair[]? tags) { if (tags is not null) @@ -57,10 +57,11 @@ public Measurement(T value, params KeyValuePair[]? tags) } /// - /// Initializes a new instance of the Measurement using the value and the list of tags. + /// Initializes a new instance of Measurement with the provided and a containing + /// zero or more associated . /// - /// The measurement value. - /// The measurement associated tags list. + /// The value of the measurement. + /// The tags associated with the measurement. public Measurement(T value, params ReadOnlySpan> tags) { _tags = tags.ToArray(); @@ -68,12 +69,33 @@ public Measurement(T value, params ReadOnlySpan> t } /// - /// Gets the measurement tags list. + /// Initializes a new instance of the Measurement with the provided and a containing + /// zero or more associated . + /// + /// The value of the measurement. + /// A containing the tags associated with the measurement. + public Measurement(T value, in TagList tags) + { + if (tags.Count > 0) + { + _tags = new KeyValuePair[tags.Count]; + tags.CopyTo(_tags.AsSpan()); + } + else + { + _tags = Instrument.EmptyTags; + } + + Value = value; + } + + /// + /// Gets the tags associated with the measurement. /// public ReadOnlySpan> Tags => _tags.AsSpan(); /// - /// Gets the measurement value. + /// Gets the value of the measurement. /// public T Value { get; }