34 lines
993 B
TypeScript
34 lines
993 B
TypeScript
/**
|
|
* Test setup for @suaveplan/api-plugin-campaigns.
|
|
*
|
|
* Installs a real in-memory OpenTelemetry MeterProvider BEFORE any
|
|
* source module imports so the meter resolved on first call binds to
|
|
* it.
|
|
*/
|
|
import { metrics } from "@opentelemetry/api";
|
|
import {
|
|
AggregationTemporality,
|
|
InMemoryMetricExporter,
|
|
MeterProvider,
|
|
PeriodicExportingMetricReader,
|
|
} from "@opentelemetry/sdk-metrics";
|
|
|
|
export const testInMemoryMetricExporter = new InMemoryMetricExporter(
|
|
AggregationTemporality.CUMULATIVE
|
|
);
|
|
|
|
const reader = new PeriodicExportingMetricReader({
|
|
exporter: testInMemoryMetricExporter,
|
|
exportIntervalMillis: 60_000,
|
|
});
|
|
|
|
export const testMeterProvider = new MeterProvider({ readers: [reader] });
|
|
metrics.setGlobalMeterProvider(testMeterProvider);
|
|
|
|
export async function flushTestMetrics() {
|
|
await testMeterProvider.forceFlush();
|
|
const collected = testInMemoryMetricExporter.getMetrics();
|
|
testInMemoryMetricExporter.reset();
|
|
return collected;
|
|
}
|