Compono.Metrics.CapturingMeterFactory
Compono.Metrics¶
Compono.Metrics¶
CapturingMeterFactory Class¶
A hand-written, reflection-free System.Diagnostics.Metrics.IMeterFactory that captures the measurements of every instrument its meters publish into an inspectable, thread-safe, Compono-native model (CapturedMeasurement<T>). Directly, publicly constructible - composing through UseMetrics(this CompositionBuilder) is not required. See docs/adr/0072-compono-metrics-testing-support-package.md.
public sealed class CapturingMeterFactory : System.Diagnostics.Metrics.IMeterFactory, System.IDisposable
Inheritance System.Object → CapturingMeterFactory
Implements System.Diagnostics.Metrics.IMeterFactory, System.IDisposable
Remarks¶
Factory semantics match DefaultMeterFactory: Create(MeterOptions) rejects a nullSystem.Diagnostics.Metrics.MeterOptions and a foreign System.Diagnostics.Metrics.MeterOptions.Scope, throws System.ObjectDisposedException after disposal, never mutates the caller's options, and caches meters by name, version, and order-insensitive tag set (duplicate tag keys are significant - see Create(MeterOptions)). Disposing a System.Diagnostics.Metrics.Meter a consumer obtained from Create(MeterOptions) is a no-op: the factory owns the meter's lifetime and releases it on Dispose().
Each factory owns one lazily created System.Diagnostics.Metrics.MeterListener, created on the first Create(MeterOptions) and disposed with the factory. It enables only instruments whose System.Diagnostics.Metrics.Meter.Scope is this factory, so two factories never see each other's measurements even for identical meter and instrument names. There is no static or shared capture state.
Disposal is the test's responsibility (System.Diagnostics.Metrics.IMeterFactory already extends System.IDisposable); composition never disposes the factory. An undisposed factory that created meters stays referenced by the BCL's static meter list for the process lifetime - the same cost as an undisposed DefaultMeterFactory.
| Constructors | |
|---|---|
| CapturingMeterFactory() | Creates a standalone CapturingMeterFactory, usable with no Compono composition involved at all. |
| Methods | |
|---|---|
| Create(MeterOptions) | Creates a System.Diagnostics.Metrics.Meter bound to this factory. The same name, version, and tag set (order-insensitive, System.Object.Equals(System.Object,System.Object) on values) returns the same System.Diagnostics.Metrics.Meter; anything else creates a new one. Duplicate tag keys are significant: [k=1, k=1] is a different set from [k=1, j=2]. |
| Dispose() | Disposes every meter this factory created (raising MeasurementsCompleted), then its System.Diagnostics.Metrics.MeterListener. Idempotent and thread-safe. Captured measurements stay readable afterwards; measurements recorded on the disposed meters' instruments are no longer captured. Disposing a System.Diagnostics.Metrics.Meter a consumer obtained from Create(MeterOptions) is a no-op - the factory owns the meter's lifetime, matching DefaultMeterFactory. |