From a793321c623a79b89caacb720f3cdaa64addc095 Mon Sep 17 00:00:00 2001 From: Aaron Abbott Date: Tue, 29 Aug 2023 08:37:14 -0400 Subject: [PATCH] feat: update PeriodicExportingMetricReader and PrometheusExporter to accept optional metric producers (#4077) Co-authored-by: Daniel Dyla Co-authored-by: Marc Pichler --- CHANGELOG.md | 1 + experimental/CHANGELOG.md | 2 ++ .../src/PrometheusExporter.ts | 1 + .../src/export/types.ts | 10 ++++++++++ .../src/export/PeriodicExportingMetricReader.ts | 9 +++++++++ 5 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72e7508827..ec685bdbb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :rocket: (Enhancement) * feat(sdk-metrics): implement MetricProducer specification [#4007](https://github.com/open-telemetry/opentelemetry-js/pull/4007) +* feat: update PeriodicExportingMetricReader and PrometheusExporter to accept optional metric producers [#4077](https://github.com/open-telemetry/opentelemetry-js/pull/4077) @aabmass ### :bug: (Bug Fix) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 0c4f724d83..3972a9b75a 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -18,6 +18,8 @@ All notable changes to experimental packages in this project will be documented ### :rocket: (Enhancement) +* feat: update PeriodicExportingMetricReader and PrometheusExporter to accept optional metric producers [#4077](https://github.com/open-telemetry/opentelemetry-js/pull/4077) @aabmass + ### :bug: (Bug Fix) ### :books: (Refine Doc) diff --git a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts index 8f84c5134c..42e4fc41e8 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts @@ -62,6 +62,7 @@ export class PrometheusExporter extends MetricReader { aggregationSelector: _instrumentType => Aggregation.Default(), aggregationTemporalitySelector: _instrumentType => AggregationTemporality.CUMULATIVE, + metricProducers: config.metricProducers, }); this._host = config.host || diff --git a/experimental/packages/opentelemetry-exporter-prometheus/src/export/types.ts b/experimental/packages/opentelemetry-exporter-prometheus/src/export/types.ts index f43c456813..78721a90c0 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/src/export/types.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/src/export/types.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +import { MetricProducer } from '@opentelemetry/sdk-metrics'; + /** * Configuration interface for prometheus exporter */ @@ -56,4 +58,12 @@ export interface ExporterConfig { * @default false */ preventServerStart?: boolean; + + /** + * **Note, this option is experimental**. Additional MetricProducers to use as a source of + * aggregated metric data in addition to the SDK's metric data. The resource returned by + * these MetricProducers is ignored; the SDK's resource will be used instead. + * @experimental + */ + metricProducers?: MetricProducer[]; } diff --git a/packages/sdk-metrics/src/export/PeriodicExportingMetricReader.ts b/packages/sdk-metrics/src/export/PeriodicExportingMetricReader.ts index 2371ecb67f..5ecafff682 100644 --- a/packages/sdk-metrics/src/export/PeriodicExportingMetricReader.ts +++ b/packages/sdk-metrics/src/export/PeriodicExportingMetricReader.ts @@ -25,6 +25,7 @@ import { MetricReader } from './MetricReader'; import { PushMetricExporter } from './MetricExporter'; import { callWithTimeout, TimeoutError } from '../utils'; import { diag } from '@opentelemetry/api'; +import { MetricProducer } from './MetricProducer'; export type PeriodicExportingMetricReaderOptions = { /** @@ -40,6 +41,13 @@ export type PeriodicExportingMetricReaderOptions = { * Milliseconds for the async observable callback to timeout. */ exportTimeoutMillis?: number; + /** + * **Note, this option is experimental**. Additional MetricProducers to use as a source of + * aggregated metric data in addition to the SDK's metric data. The resource returned by + * these MetricProducers is ignored; the SDK's resource will be used instead. + * @experimental + */ + metricProducers?: MetricProducer[]; }; /** @@ -59,6 +67,7 @@ export class PeriodicExportingMetricReader extends MetricReader { ), aggregationTemporalitySelector: options.exporter.selectAggregationTemporality?.bind(options.exporter), + metricProducers: options.metricProducers, }); if (