UNPKG

@shopify/cli-kit

Version:

A set of utilities, interfaces, and models that are common across all the platform features

34 lines 1.42 kB
import { MetricReader } from '@opentelemetry/sdk-metrics'; import { ExportResultCode } from '@opentelemetry/core'; import { diag } from '@opentelemetry/api'; import { throttle } from '../utils/throttle.js'; export class InstantaneousMetricReader extends MetricReader { constructor({ exporter, throttleLimit }) { super({ aggregationSelector: exporter.selectAggregation?.bind(exporter), aggregationTemporalitySelector: exporter.selectAggregationTemporality?.bind(exporter), }); this._exporter = exporter; this.onForceFlush = throttle( // eslint-disable-next-line @typescript-eslint/unbound-method this.onForceFlush, throttleLimit); } async onForceFlush() { const { resourceMetrics, errors } = await this.collect({}); if (errors.length > 0) { diag.error('InstantaneousMetricReader: metrics collection errors', ...errors); } return new Promise((resolve) => { this._exporter.export(resourceMetrics, (result) => { if (result.code !== ExportResultCode.SUCCESS) { diag.error('InstantaneousMetricReader: metrics export failed', result.error); } resolve(); }); }); } async onShutdown() { await this._exporter.shutdown(); } } //# sourceMappingURL=InstantaneousMetricReader.js.map