{"version":3,"file":"AsyncMetricStorage.mjs","names":[],"sources":["../../src/state/AsyncMetricStorage.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HrTime } from '@opentelemetry/api';\nimport type { Accumulation, Aggregator } from '../aggregator/types';\nimport type { InstrumentDescriptor } from '../InstrumentDescriptor';\nimport { MetricStorage } from './MetricStorage';\nimport type { MetricData } from '../export/MetricData';\nimport { DeltaMetricProcessor } from './DeltaMetricProcessor';\nimport { TemporalMetricProcessor } from './TemporalMetricProcessor';\nimport type { Maybe } from '../utils';\nimport type { MetricCollectorHandle } from './MetricCollector';\nimport { AttributeHashMap } from './HashMap';\nimport type { AsyncWritableMetricStorage } from './WritableMetricStorage';\nimport type { IAttributesProcessor } from '../view/AttributesProcessor';\n\n/**\n * Internal interface.\n *\n * Stores and aggregates {@link MetricData} for asynchronous instruments.\n */\nexport class AsyncMetricStorage<T extends Maybe<Accumulation>>\n  extends MetricStorage\n  implements AsyncWritableMetricStorage\n{\n  private _aggregationCardinalityLimit?: number;\n  private _deltaMetricStorage: DeltaMetricProcessor<T>;\n  private _temporalMetricStorage: TemporalMetricProcessor<T>;\n  private _attributesProcessor?: IAttributesProcessor;\n\n  constructor(\n    _instrumentDescriptor: InstrumentDescriptor,\n    aggregator: Aggregator<T>,\n    attributesProcessor: IAttributesProcessor | undefined,\n    collectorHandles: MetricCollectorHandle[],\n    aggregationCardinalityLimit?: number\n  ) {\n    super(_instrumentDescriptor);\n    this._aggregationCardinalityLimit = aggregationCardinalityLimit;\n    this._deltaMetricStorage = new DeltaMetricProcessor(\n      aggregator,\n      this._aggregationCardinalityLimit\n    );\n    this._temporalMetricStorage = new TemporalMetricProcessor(\n      aggregator,\n      collectorHandles\n    );\n    this._attributesProcessor = attributesProcessor;\n  }\n\n  record(measurements: AttributeHashMap<number>, observationTime: HrTime) {\n    if (this._attributesProcessor === undefined) {\n      this._deltaMetricStorage.batchCumulate(measurements, observationTime);\n      return;\n    }\n    const processed = new AttributeHashMap<number>();\n    for (const [attributes, value] of measurements.entries()) {\n      processed.set(this._attributesProcessor.process(attributes), value);\n    }\n    this._deltaMetricStorage.batchCumulate(processed, observationTime);\n  }\n\n  /**\n   * Collects the metrics from this storage. The ObservableCallback is invoked\n   * during the collection.\n   *\n   * Note: This is a stateful operation and may reset any interval-related\n   * state for the MetricCollector.\n   */\n  collect(\n    collector: MetricCollectorHandle,\n    collectionTime: HrTime\n  ): Maybe<MetricData> {\n    const accumulations = this._deltaMetricStorage.collect();\n\n    return this._temporalMetricStorage.buildMetrics(\n      collector,\n      this._instrumentDescriptor,\n      accumulations,\n      collectionTime\n    );\n  }\n}\n"],"mappings":";;;;;;;;;;AAuBA,IAAa,qBAAb,cACU,cAEV;CACE;CACA;CACA;CACA;CAEA,YACE,uBACA,YACA,qBACA,kBACA,6BACA;EACA,MAAM,qBAAqB;EAC3B,KAAK,+BAA+B;EACpC,KAAK,sBAAsB,IAAI,qBAC7B,YACA,KAAK,4BACP;EACA,KAAK,yBAAyB,IAAI,wBAChC,YACA,gBACF;EACA,KAAK,uBAAuB;CAC9B;CAEA,OAAO,cAAwC,iBAAyB;EACtE,IAAI,KAAK,yBAAyB,KAAA,GAAW;GAC3C,KAAK,oBAAoB,cAAc,cAAc,eAAe;GACpE;EACF;EACA,MAAM,YAAY,IAAI,iBAAyB;EAC/C,KAAK,MAAM,CAAC,YAAY,UAAU,aAAa,QAAQ,GACrD,UAAU,IAAI,KAAK,qBAAqB,QAAQ,UAAU,GAAG,KAAK;EAEpE,KAAK,oBAAoB,cAAc,WAAW,eAAe;CACnE;;;;;;;;CASA,QACE,WACA,gBACmB;EACnB,MAAM,gBAAgB,KAAK,oBAAoB,QAAQ;EAEvD,OAAO,KAAK,uBAAuB,aACjC,WACA,KAAK,uBACL,eACA,cACF;CACF;AACF"}