{"version":3,"file":"SyncMetricStorage.cjs","names":["MetricStorage","DeltaMetricProcessor","TemporalMetricProcessor","contextApi"],"sources":["../../src/state/SyncMetricStorage.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Context, HrTime, Attributes } from '@opentelemetry/api';\nimport { context as contextApi } from '@opentelemetry/api';\nimport type { WritableMetricStorage } from './WritableMetricStorage';\nimport type { Accumulation, Aggregator } from '../aggregator/types';\nimport type { InstrumentDescriptor } from '../InstrumentDescriptor';\nimport type { IAttributesProcessor } from '../view/AttributesProcessor';\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';\n\n/**\n * Internal interface.\n *\n * Stores and aggregates {@link MetricData} for synchronous instruments.\n */\nexport class SyncMetricStorage<T extends Maybe<Accumulation>>\n  extends MetricStorage\n  implements WritableMetricStorage\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    this.hasAttributeProcessor = attributesProcessor !== undefined;\n  }\n\n  readonly hasAttributeProcessor: boolean;\n\n  record(\n    value: number,\n    attributes: Attributes,\n    context: Context | undefined,\n    recordTime: number\n  ) {\n    if (this._attributesProcessor !== undefined) {\n      attributes = this._attributesProcessor.process(\n        attributes,\n        context ?? contextApi.active()\n      );\n    }\n    this._deltaMetricStorage.record(value, attributes, recordTime);\n  }\n\n  /**\n   * Collects the metrics from this storage.\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,oBAAb,cACUA,sBAAAA,cAEV;CACE;CACA;CACA;CACA;CAEA,YACE,sBACA,YACA,qBACA,kBACA,6BACA;EACA,MAAM,oBAAoB;EAC1B,KAAK,+BAA+B;EACpC,KAAK,sBAAsB,IAAIC,6BAAAA,qBAC7B,YACA,KAAK,4BACP;EACA,KAAK,yBAAyB,IAAIC,gCAAAA,wBAChC,YACA,gBACF;EACA,KAAK,uBAAuB;EAC5B,KAAK,wBAAwB,wBAAwB,KAAA;CACvD;CAEA;CAEA,OACE,OACA,YACA,SACA,YACA;EACA,IAAI,KAAK,yBAAyB,KAAA,GAChC,aAAa,KAAK,qBAAqB,QACrC,YACA,WAAWC,mBAAAA,QAAW,OAAO,CAC/B;EAEF,KAAK,oBAAoB,OAAO,OAAO,YAAY,UAAU;CAC/D;;;;;;;CAQA,QACE,WACA,gBACmB;EACnB,MAAM,gBAAgB,KAAK,oBAAoB,QAAQ;EAEvD,OAAO,KAAK,uBAAuB,aACjC,WACA,KAAK,uBACL,eACA,cACF;CACF;AACF"}