Class TestMetricCollector
- Namespace
- XBullet.EasyTesting.Observability
- Assembly
- XBullet.EasyTesting.Observability.dll
Thread-safe listener that captures metric measurements in memory.
public sealed class TestMetricCollector : ITestScenarioResource, IDisposable
- Inheritance
-
TestMetricCollector
- Implements
- Inherited Members
Constructors
TestMetricCollector(TimeProvider?, IEnumerable<string>?, int)
Creates a bounded collector, optionally restricted to exact meter names.
public TestMetricCollector(TimeProvider? timeProvider = null, IEnumerable<string>? meterNames = null, int maximumMeasurements = 1000)
Parameters
timeProviderTimeProviderThe clock used for measurement timestamps, or null to use System. The provider is retained but not owned or disposed.
meterNamesIEnumerable<string>Exact, case-sensitive meter names to capture, or null or an empty sequence to capture every meter. The sequence is enumerated immediately and duplicates are ignored.
maximumMeasurementsintThe positive maximum number of measurements retained. The default is 1,000; when the bound is exceeded, the oldest measurements are discarded first.
Properties
Count
Gets the number of currently captured measurements.
public int Count { get; }
Property Value
- int
A value from zero through the configured maximum measurement count.
Measurements
Gets a stable copy of captured measurements in recording order.
public IReadOnlyList<TestMetricMeasurement> Measurements { get; }
Property Value
- IReadOnlyList<TestMetricMeasurement>
A newly allocated snapshot in recording order. The caller may retain the list. Measurements can contain unredacted tag values with sensitive or mutable data.
Methods
CaptureDiagnosticsAsync(CancellationToken)
Captures the current state before a failed scenario is cleaned up.
public ValueTask<object?> CaptureDiagnosticsAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancels diagnostic collection for this resource. The default token does not request cancellation. A thrown exception, including cancellation, is recorded as a diagnostic capture failure so cleanup can continue.
Returns
- ValueTask<object>
A serializable diagnostic value, or null when the resource has no state to report. Ownership remains with the resource unless its implementation states otherwise.
CollectObservableMeasurements()
Requests measurements from enabled observable instruments.
public void CollectObservableMeasurements()
Remarks
This synchronously invokes enabled observable-instrument callbacks and appends the values they report. Callback exceptions propagate to the caller.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Reset()
Removes every captured measurement and returns this collector.
public TestMetricCollector Reset()
Returns
- TestMetricCollector
This collector, for chaining. Its listener, filters, clock, and maximum remain unchanged.
ResetAsync(CancellationToken)
Clears mutable state before and after a scenario.
public ValueTask ResetAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancels this reset attempt. The default token does not request cancellation. The factory continues resetting the remaining registered resources and reports all reset failures together.
Returns
- ValueTask
A task that completes when the resource has finished resetting its state.
Should()
Starts a fluent assertion chain over captured measurements.
public TestMetricCollectorAssertions Should()
Returns
- TestMetricCollectorAssertions
A new assertion object that reads this collector's current snapshots.