{"version":3,"file":"ConsoleMetricExporter.mjs","names":[],"sources":["../../src/export/ConsoleMetricExporter.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { ExportResult } from '@opentelemetry/core';\nimport { ExportResultCode } from '@opentelemetry/core';\nimport type { AggregationTemporality } from './AggregationTemporality';\nimport type { ResourceMetrics, InstrumentType } from './MetricData';\nimport type { PushMetricExporter } from './MetricExporter';\nimport type { AggregationTemporalitySelector } from './AggregationSelector';\nimport { DEFAULT_AGGREGATION_TEMPORALITY_SELECTOR } from './AggregationSelector';\n\ninterface ConsoleMetricExporterOptions {\n  temporalitySelector?: AggregationTemporalitySelector;\n}\n\n/**\n * This is an implementation of {@link PushMetricExporter} that prints metrics to the\n * console. This class can be used for diagnostic purposes.\n *\n * NOTE: This {@link PushMetricExporter} is intended for diagnostics use only, output rendered to the console may change at any time.\n */\n\n/* eslint-disable no-console */\nexport class ConsoleMetricExporter implements PushMetricExporter {\n  protected _shutdown = false;\n  protected _temporalitySelector: AggregationTemporalitySelector;\n\n  constructor(options?: ConsoleMetricExporterOptions) {\n    this._temporalitySelector =\n      options?.temporalitySelector ?? DEFAULT_AGGREGATION_TEMPORALITY_SELECTOR;\n  }\n\n  export(\n    metrics: ResourceMetrics,\n    resultCallback: (result: ExportResult) => void\n  ): void {\n    if (this._shutdown) {\n      // If the exporter is shutting down, by spec, we need to return FAILED as export result\n      resultCallback({ code: ExportResultCode.FAILED });\n      return;\n    }\n\n    return ConsoleMetricExporter._sendMetrics(metrics, resultCallback);\n  }\n\n  forceFlush(): Promise<void> {\n    return Promise.resolve();\n  }\n\n  selectAggregationTemporality(\n    _instrumentType: InstrumentType\n  ): AggregationTemporality {\n    return this._temporalitySelector(_instrumentType);\n  }\n\n  shutdown(): Promise<void> {\n    this._shutdown = true;\n    return Promise.resolve();\n  }\n\n  private static _sendMetrics(\n    metrics: ResourceMetrics,\n    done: (result: ExportResult) => void\n  ): void {\n    for (const scopeMetrics of metrics.scopeMetrics) {\n      for (const metric of scopeMetrics.metrics) {\n        console.dir(\n          {\n            descriptor: metric.descriptor,\n            dataPointType: metric.dataPointType,\n            dataPoints: metric.dataPoints,\n          },\n          { depth: null }\n        );\n      }\n    }\n\n    done({ code: ExportResultCode.SUCCESS });\n  }\n}\n"],"mappings":";;;;;;;;;AAwBA,IAAa,wBAAb,MAAa,sBAAoD;CAC/D,YAAsB;CACtB;CAEA,YAAY,SAAwC;EAClD,KAAK,uBACH,SAAS,uBAAuB;CACpC;CAEA,OACE,SACA,gBACM;EACN,IAAI,KAAK,WAAW;GAElB,eAAe,EAAE,MAAM,iBAAiB,OAAO,CAAC;GAChD;EACF;EAEA,OAAO,sBAAsB,aAAa,SAAS,cAAc;CACnE;CAEA,aAA4B;EAC1B,OAAO,QAAQ,QAAQ;CACzB;CAEA,6BACE,iBACwB;EACxB,OAAO,KAAK,qBAAqB,eAAe;CAClD;CAEA,WAA0B;EACxB,KAAK,YAAY;EACjB,OAAO,QAAQ,QAAQ;CACzB;CAEA,OAAe,aACb,SACA,MACM;EACN,KAAK,MAAM,gBAAgB,QAAQ,cACjC,KAAK,MAAM,UAAU,aAAa,SAChC,QAAQ,IACN;GACE,YAAY,OAAO;GACnB,eAAe,OAAO;GACtB,YAAY,OAAO;EACrB,GACA,EAAE,OAAO,KAAK,CAChB;EAIJ,KAAK,EAAE,MAAM,iBAAiB,QAAQ,CAAC;CACzC;AACF"}