<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="10.0.0-preview.1.25080.5" />

Instrument<T>

public abstract class Instrument<T> : Instrument where T : struct
The base class for all non-observable instruments.
using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Diagnostics.Metrics { [DebuggerDisplay("Name = {Name}, Meter = {Meter.Name}")] public abstract class Instrument<T> : Instrument where T : struct { [Nullable(new byte[] { 2, 0 })] public InstrumentAdvice<T> Advice { [return: Nullable(new byte[] { 2, 0 })] get; } [NullableContext(1)] protected Instrument(Meter meter, string name) : this(meter, name, (string)null, (string)null, (IEnumerable<KeyValuePair<string, object>>)null, (InstrumentAdvice<T>)null) { } [NullableContext(1)] [EditorBrowsable(EditorBrowsableState.Never)] protected Instrument(Meter meter, string name, [Nullable(2)] string unit, [Nullable(2)] string description) : this(meter, name, unit, description, (IEnumerable<KeyValuePair<string, object>>)null, (InstrumentAdvice<T>)null) { } [NullableContext(1)] [EditorBrowsable(EditorBrowsableState.Never)] protected Instrument(Meter meter, string name, [Nullable(2)] string unit, [Nullable(2)] string description, [Nullable(new byte[] { 2, 0, 1, 2 })] IEnumerable<KeyValuePair<string, object>> tags) : this(meter, name, unit, description, tags, (InstrumentAdvice<T>)null) { } [NullableContext(1)] protected Instrument(Meter meter, string name, [Nullable(2)] string unit = null, [Nullable(2)] string description = null, [Nullable(new byte[] { 2, 0, 1, 2 })] IEnumerable<KeyValuePair<string, object>> tags = null, [Nullable(new byte[] { 2, 0 })] InstrumentAdvice<T> advice = null) : base(meter, name, unit, description, tags) { Advice = advice; Instrument.ValidateTypeParameter<T>(); } protected void RecordMeasurement(T measurement) { RecordMeasurement(measurement, MemoryExtensions.AsSpan<KeyValuePair<string, object>>(Instrument.EmptyTags)); } protected void RecordMeasurement(T measurement, [Nullable(new byte[] { 0, 0, 1, 2 })] ReadOnlySpan<KeyValuePair<string, object>> tags) { for (DiagNode<ListenerSubscription> diagNode = _subscriptions.First; diagNode != null; diagNode = diagNode.Next) { diagNode.Value.Listener.NotifyMeasurement<T>((Instrument)this, measurement, tags, diagNode.Value.State); } } protected void RecordMeasurement(T measurement, [Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag) { KeyValuePair<string, object> reference = tag; RecordMeasurement(measurement, new ReadOnlySpan<KeyValuePair<string, object>>(ref reference)); } protected void RecordMeasurement(T measurement, [Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag1, [Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag2) { global::<>y__InlineArray2<KeyValuePair<string, object>> buffer = default(global::<>y__InlineArray2<KeyValuePair<string, object>>); global::<PrivateImplementationDetails>.InlineArrayElementRef<global::<>y__InlineArray2<KeyValuePair<string, object>>, KeyValuePair<string, object>>(ref buffer, 0) = tag1; global::<PrivateImplementationDetails>.InlineArrayElementRef<global::<>y__InlineArray2<KeyValuePair<string, object>>, KeyValuePair<string, object>>(ref buffer, 1) = tag2; RecordMeasurement(measurement, global::<PrivateImplementationDetails>.InlineArrayAsReadOnlySpan<global::<>y__InlineArray2<KeyValuePair<string, object>>, KeyValuePair<string, object>>(ref buffer, 2)); } protected void RecordMeasurement(T measurement, [Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag1, [Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag2, [Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag3) { global::<>y__InlineArray3<KeyValuePair<string, object>> buffer = default(global::<>y__InlineArray3<KeyValuePair<string, object>>); global::<PrivateImplementationDetails>.InlineArrayElementRef<global::<>y__InlineArray3<KeyValuePair<string, object>>, KeyValuePair<string, object>>(ref buffer, 0) = tag1; global::<PrivateImplementationDetails>.InlineArrayElementRef<global::<>y__InlineArray3<KeyValuePair<string, object>>, KeyValuePair<string, object>>(ref buffer, 1) = tag2; global::<PrivateImplementationDetails>.InlineArrayElementRef<global::<>y__InlineArray3<KeyValuePair<string, object>>, KeyValuePair<string, object>>(ref buffer, 2) = tag3; RecordMeasurement(measurement, global::<PrivateImplementationDetails>.InlineArrayAsReadOnlySpan<global::<>y__InlineArray3<KeyValuePair<string, object>>, KeyValuePair<string, object>>(ref buffer, 3)); } protected void RecordMeasurement(T measurement, [In] [IsReadOnly] ref TagList tagList) { RecordMeasurement(measurement, tagList.Tags); } } }