UNPKG

@opentelemetry/sdk-metrics

Version:
49 lines 2.19 kB
"use strict"; /* * Copyright The OpenTelemetry Authors * SPDX-License-Identifier: Apache-2.0 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.AsyncMetricStorage = void 0; const MetricStorage_1 = require("./MetricStorage"); const DeltaMetricProcessor_1 = require("./DeltaMetricProcessor"); const TemporalMetricProcessor_1 = require("./TemporalMetricProcessor"); const HashMap_1 = require("./HashMap"); /** * Internal interface. * * Stores and aggregates {@link MetricData} for asynchronous instruments. */ class AsyncMetricStorage extends MetricStorage_1.MetricStorage { _aggregationCardinalityLimit; _deltaMetricStorage; _temporalMetricStorage; _attributesProcessor; constructor(_instrumentDescriptor, aggregator, attributesProcessor, collectorHandles, aggregationCardinalityLimit) { super(_instrumentDescriptor); this._aggregationCardinalityLimit = aggregationCardinalityLimit; this._deltaMetricStorage = new DeltaMetricProcessor_1.DeltaMetricProcessor(aggregator, this._aggregationCardinalityLimit); this._temporalMetricStorage = new TemporalMetricProcessor_1.TemporalMetricProcessor(aggregator, collectorHandles); this._attributesProcessor = attributesProcessor; } record(measurements, observationTime) { const processed = new HashMap_1.AttributeHashMap(); for (const [attributes, value] of measurements.entries()) { processed.set(this._attributesProcessor.process(attributes), value); } this._deltaMetricStorage.batchCumulate(processed, observationTime); } /** * Collects the metrics from this storage. The ObservableCallback is invoked * during the collection. * * Note: This is a stateful operation and may reset any interval-related * state for the MetricCollector. */ collect(collector, collectionTime) { const accumulations = this._deltaMetricStorage.collect(); return this._temporalMetricStorage.buildMetrics(collector, this._instrumentDescriptor, accumulations, collectionTime); } } exports.AsyncMetricStorage = AsyncMetricStorage; //# sourceMappingURL=AsyncMetricStorage.js.map