Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ public sealed class InstrumentAdvice<T> where T : struct
public Measurement(T value, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object?>>? tags) { throw null; }
public Measurement(T value, params System.Collections.Generic.KeyValuePair<string, object?>[]? tags) { throw null; }
public Measurement(T value, params System.ReadOnlySpan<System.Collections.Generic.KeyValuePair<string, object?>> tags) { throw null; }
public Measurement(T value, in System.Diagnostics.TagList tags) { throw null; }
public ReadOnlySpan<System.Collections.Generic.KeyValuePair<string, object?>> Tags { get { throw null; } }
public T Value { get { throw null; } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@
namespace System.Diagnostics.Metrics
{
/// <summary>
/// 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.
/// <see cref="Measurement{T}"/> stores one observed value and its associated tags for a metric.
/// Observable instruments use this type when reporting current measurements from their <see cref="ObservableInstrument{T}.Observe()"/> implementation.
/// </summary>
public readonly struct Measurement<T> where T : struct
{
private readonly KeyValuePair<string, object?>[] _tags;

/// <summary>
/// Initializes a new instance of the Measurement using the value and the list of tags.
/// Initializes a new instance of <see cref="Measurement{T}"/> with the provided <paramref name="value"/>.
/// </summary>
/// <param name="value">The measurement value.</param>
/// <param name="value">The value of the measurement.</param>
public Measurement(T value)
{
_tags = Instrument.EmptyTags;
Value = value;
}

/// <summary>
/// Initializes a new instance of the Measurement using the value and the list of tags.
/// Initializes a new instance of Measurement with the provided <paramref name="value"/> and zero or more associated <paramref name="tags"/>.
/// </summary>
/// <param name="value">The measurement value.</param>
/// <param name="tags">The measurement associated tags list.</param>
/// <param name="value">The value of the measurement.</param>
/// <param name="tags">The <see cref="KeyValuePair{TKey, TValue}"/> tags associated with the measurement.</param>
public Measurement(T value, IEnumerable<KeyValuePair<string, object?>>? tags)
{
_tags = ToArray(tags);
Value = value;
}

/// <summary>
/// Initializes a new instance of the Measurement using the value and the list of tags.
/// Initializes a new instance of Measurement with the provided <paramref name="value"/> and zero or more associated <paramref name="tags"/>.
/// </summary>
/// <param name="value">The measurement value.</param>
/// <param name="tags">The measurement associated tags list.</param>
/// <param name="value">The value of the measurement.</param>
/// <param name="tags">The <see cref="KeyValuePair{TKey, TValue}"/> tags associated with the measurement.</param>
public Measurement(T value, params KeyValuePair<string, object?>[]? tags)
{
if (tags is not null)
Expand All @@ -57,23 +57,45 @@ public Measurement(T value, params KeyValuePair<string, object?>[]? tags)
}

/// <summary>
/// Initializes a new instance of the Measurement using the value and the list of tags.
/// Initializes a new instance of Measurement with the provided <paramref name="value"/> and a <see cref="ReadOnlySpan{T}"/> containing
/// zero or more associated <paramref name="tags"/>.
/// </summary>
/// <param name="value">The measurement value.</param>
/// <param name="tags">The measurement associated tags list.</param>
/// <param name="value">The value of the measurement.</param>
/// <param name="tags">The <see cref="KeyValuePair{TKey, TValue}"/> tags associated with the measurement.</param>
public Measurement(T value, params ReadOnlySpan<KeyValuePair<string, object?>> tags)
{
_tags = tags.ToArray();
Value = value;
}

/// <summary>
/// Gets the measurement tags list.
/// Initializes a new instance of the Measurement with the provided <paramref name="value"/> and a <see cref="TagList"/> containing
/// zero or more associated <paramref name="tags"/>.
/// </summary>
/// <param name="value">The value of the measurement.</param>
/// <param name="tags">A <see cref="TagList"/> containing the <see cref="KeyValuePair{TKey, TValue}"/> tags associated with the measurement.</param>
public Measurement(T value, in TagList tags)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests for this? I don't see any in this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var measurement = new Measurement<int>(i, tags);

{
if (tags.Count > 0)
{
_tags = new KeyValuePair<string, object?>[tags.Count];
tags.CopyTo(_tags.AsSpan());
}
else
{
_tags = Instrument.EmptyTags;
}

Value = value;
}

/// <summary>
/// Gets the tags associated with the measurement.
/// </summary>
public ReadOnlySpan<KeyValuePair<string, object?>> Tags => _tags.AsSpan();

/// <summary>
/// Gets the measurement value.
/// Gets the value of the measurement.
/// </summary>
public T Value { get; }

Expand Down