Class MeterCapture
- Namespace
- MetricsAssertions
- Assembly
- MetricsAssertions.dll
A meter-wide measurement capture composed from a bundle of per-instrument InstrumentCapture (each backed by a Microsoft.Extensions.Diagnostics.Metrics.Testing.MetricCollector<T>). Built fluently for a known instrument set - strongly typed at construction, uniform to query and assert - for tests that need to assert across several instruments of one meter at once (e.g. an observable-gauge scrape).
Build with For(string) + Add*; query per instrument via the indexer or
CounterTotal(string) / Samples(string) / MeasurementCount(string), or across all via
Measurements. Call RecordObservable() before reading observable gauges.
public sealed class MeterCapture : IDisposable
- Inheritance
-
MeterCapture
- Implements
- Inherited Members
- Extension Methods
Properties
this[string]
Gets the per-instrument capture for instrumentName.
public InstrumentCapture this[string instrumentName] { get; }
Parameters
instrumentNamestringThe instrument name added to the bundle.
Property Value
Measurements
Gets every captured measurement across all bundled instruments as a queryable, assertable set.
public MeasurementSet Measurements { get; }
Property Value
MeterName
Gets the meter name this capture is scoped to.
public string MeterName { get; }
Property Value
Methods
Add<T>(Instrument<T>, TimeProvider?)
Adds the referenceable instrument to the bundle.
public MeterCapture Add<T>(Instrument<T> instrument, TimeProvider? timeProvider = null) where T : struct
Parameters
instrumentInstrument<T>The instrument to capture.
timeProviderTimeProviderAn optional clock for measurement timestamps and waits.
Returns
Type Parameters
TThe instrument's value type.
Add<T>(string, TimeProvider?)
Adds the named instrument (typically a counter / up-down counter / histogram) to the bundle.
public MeterCapture Add<T>(string instrumentName, TimeProvider? timeProvider = null) where T : struct
Parameters
instrumentNamestringThe instrument name.
timeProviderTimeProviderAn optional clock for measurement timestamps and waits.
Returns
Type Parameters
TThe instrument's value type.
Contains(string)
Returns whether an instrument named instrumentName is bundled.
public bool Contains(string instrumentName)
Parameters
instrumentNamestringThe instrument name to look for.
Returns
CounterTotal(string)
Gets the net total for a bundled counter / up-down counter.
public long CounterTotal(string instrumentName)
Parameters
instrumentNamestringThe instrument name.
Returns
Dispose()
Releases every bundled collector.
public void Dispose()
For(string)
Begins building a capture for the meter named meterName created
directly (new Meter(name), no scope). For a meter created by an
IMeterFactory, use For(string, object?).
public static MeterCapture For(string meterName)
Parameters
meterNamestringThe meter name to capture.
Returns
For(string, object?)
Begins building a capture for the meter named meterName whose
Scope equals meterScope. Pass the
IMeterFactory instance for a DI-created meter; a null scope
only matches a directly-created meter and would capture nothing from a factory-created one.
public static MeterCapture For(string meterName, object? meterScope)
Parameters
meterNamestringThe meter name to capture.
meterScopeobjectThe meter scope to match (the
IMeterFactoryinstance, or null).
Returns
HasMeasurementTagged(string, string, object?)
Returns whether a bundled instrument has a measurement tagged tagKey=tagValue.
public bool HasMeasurementTagged(string instrumentName, string tagKey, object? tagValue)
Parameters
instrumentNamestringThe instrument name.
tagKeystringThe tag key to match.
tagValueobjectThe tag value to match.
Returns
MeasurementCount(string)
Gets the measurement count for a bundled instrument.
public int MeasurementCount(string instrumentName)
Parameters
instrumentNamestringThe instrument name.
Returns
RecordObservable()
Pulls the current values of all bundled observable instruments (gauges).
public void RecordObservable()
Samples(string)
Gets the samples for a bundled histogram.
public IReadOnlyList<double> Samples(string instrumentName)
Parameters
instrumentNamestringThe instrument name.