Connectum API Reference / @connectum/testing / index / InMemoryMetricCollector
Class: InMemoryMetricCollector ​
Defined in: testing/src/otel-collectors.ts:227
In-memory metric collector. Owns its own MeterProvider and periodic reader. flush() performs a forced collect+export cycle synchronously (via forceFlush) and returns the normalized data.
Register collector.provider with metrics.setGlobalMeterProvider() and call metrics.disable() when done, exactly as for InMemorySpanCollector (or let withTelemetry do it). The same two requirements apply to collecting the metrics of @connectum/otel interceptors: run with OTEL_METRICS_EXPORTER=none, and call shutdownProvider() from @connectum/otel at the start of every scenario, otherwise the scenario records nothing.
Constructors ​
Constructor ​
new InMemoryMetricCollector():
InMemoryMetricCollector
Defined in: testing/src/otel-collectors.ts:233
Returns ​
InMemoryMetricCollector
Properties ​
exporter ​
readonlyexporter:InMemoryMetricExporter
Defined in: testing/src/otel-collectors.ts:228
provider ​
readonlyprovider:MeterProvider
Defined in: testing/src/otel-collectors.ts:229
reader ​
readonlyreader:PeriodicExportingMetricReader
Defined in: testing/src/otel-collectors.ts:230
Methods ​
dispose() ​
dispose():
Promise<void>
Defined in: testing/src/otel-collectors.ts:283
Shut the provider down. Calling it again is a no-op.
Returns ​
Promise<void>
flush() ​
flush():
Promise<NormalizedMetric[]>
Defined in: testing/src/otel-collectors.ts:256
Force a collect+export cycle and return what was recorded since the previous flush() (or since the collector was created or reset()), normalized. The exporter's buffer is emptied by the read, so a flush with nothing recorded in between returns [] and a lookup by name after a later flush sees the current value, never an earlier export of the same metric.
Returns ​
Promise<NormalizedMetric[]>
Throws ​
Error when called after InMemoryMetricCollector.dispose
reset() ​
reset():
void
Defined in: testing/src/otel-collectors.ts:278
Forget what was exported and not yet returned by flush().
Returns ​
void