-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Gauge Metrics Instrument (#103543)
* Add Gauge Metrics Instrument * Addressing the feedback * Apply suggestions from code review Co-authored-by: Cijo Thomas <cithomas@microsoft.com> --------- Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
- Loading branch information
1 parent
eb14da9
commit c529580
Showing
7 changed files
with
424 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Gauge.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace System.Diagnostics.Metrics | ||
{ | ||
/// <summary> | ||
/// The Gauge is an instrument used to record non-additive values whenever changes occur. For example, record the room background noise level value when changes occur. | ||
/// </summary> | ||
/// <remarks> | ||
/// This class supports only the following generic parameter types: <see cref="byte" />, <see cref="short" />, <see cref="int" />, <see cref="long" />, <see cref="float" />, <see cref="double" />, and <see cref="decimal" /> | ||
/// </remarks> | ||
public sealed class Gauge<T> : Instrument<T> where T : struct | ||
{ | ||
internal Gauge(Meter meter, string name, string? unit, string? description) : this(meter, name, unit, description, null) | ||
{ | ||
} | ||
|
||
internal Gauge(Meter meter, string name, string? unit, string? description, IEnumerable<KeyValuePair<string, object?>>? tags) : base(meter, name, unit, description, tags) | ||
{ | ||
Publish(); | ||
} | ||
|
||
/// <summary> | ||
/// Record the Gauge current value. | ||
/// </summary> | ||
/// <param name="value">The Gauge current value.</param> | ||
public void Record(T value) => RecordMeasurement(value); | ||
|
||
/// <summary> | ||
/// Record the Gauge current value. | ||
/// </summary> | ||
/// <param name="value">The Gauge current value.</param> | ||
/// <param name="tag">A key-value pair tag associated with the measurement.</param> | ||
public void Record(T value, KeyValuePair<string, object?> tag) => RecordMeasurement(value, tag); | ||
|
||
/// <summary> | ||
/// Record the Gauge current value. | ||
/// </summary> | ||
/// <param name="value">The Gauge current value.</param> | ||
/// <param name="tag1">A first key-value pair tag associated with the measurement.</param> | ||
/// <param name="tag2">A second key-value pair tag associated with the measurement.</param> | ||
public void Record(T value, KeyValuePair<string, object?> tag1, KeyValuePair<string, object?> tag2) => RecordMeasurement(value, tag1, tag2); | ||
|
||
/// <summary> | ||
/// Record the Gauge current value. | ||
/// </summary> | ||
/// <param name="value">The Gauge current value.</param> | ||
/// <param name="tag1">A first key-value pair tag associated with the measurement.</param> | ||
/// <param name="tag2">A second key-value pair tag associated with the measurement.</param> | ||
/// <param name="tag3">A third key-value pair tag associated with the measurement.</param> | ||
public void Record(T value, KeyValuePair<string, object?> tag1, KeyValuePair<string, object?> tag2, KeyValuePair<string, object?> tag3) => RecordMeasurement(value, tag1, tag2, tag3); | ||
|
||
/// <summary> | ||
/// Record the Gauge current value. | ||
/// </summary> | ||
/// <param name="value">The Gauge current value.</param> | ||
/// <param name="tags">A span of key-value pair tags associated with the measurement.</param> | ||
public void Record(T value, params ReadOnlySpan<KeyValuePair<string, object?>> tags) => RecordMeasurement(value, tags); | ||
|
||
/// <summary> | ||
/// Record the Gauge current value. | ||
/// </summary> | ||
/// <param name="value">The Gauge current value.</param> | ||
/// <param name="tags">A list of key-value pair tags associated with the measurement.</param> | ||
public void Record(T value, params KeyValuePair<string, object?>[] tags) => RecordMeasurement(value, tags.AsSpan()); | ||
|
||
/// <summary> | ||
/// Record the Gauge current value. | ||
/// </summary> | ||
/// <param name="value">The Gauge current value.</param> | ||
/// <param name="tagList">A <see cref="T:System.Diagnostics.TagList" /> of tags associated with the measurement.</param> | ||
public void Record(T value, in TagList tagList) => RecordMeasurement(value, in tagList); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.