From 6410ca1e19686a83c4b1302963540a7170c6ed7d Mon Sep 17 00:00:00 2001 From: Jackson Weber <47067795+JacksonWeber@users.noreply.github.com> Date: Mon, 12 Dec 2022 23:45:13 -0800 Subject: [PATCH] fix(prometheus-serializer): correct string used for NaN (#3477) --- experimental/CHANGELOG.md | 1 + .../src/PrometheusSerializer.ts | 2 +- .../test/PrometheusSerializer.test.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index a45f89af66..0fa4a148e4 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -19,6 +19,7 @@ All notable changes to experimental packages in this project will be documented * fix(instrumentation): only call `onRequire` for full matches on core modules with sub-paths [#3451](https://github.com/open-telemetry/opentelemetry-js/pull/3451) @mhassan1 * fix(instrumentation): add back support for absolute paths via `require-in-the-middle` [#3457](https://github.com/open-telemetry/opentelemetry-js/pull/3457) @mhassan1 * fix(prometheus-sanitization): replace repeated `_` with a single `_` [3470](https://github.com/open-telemetry/opentelemetry-js/pull/3470) @samimusallam +* fix(prometheus-serializer): correct string used for NaN [#3477](https://github.com/open-telemetry/opentelemetry-js/pull/3477) @JacksonWeber ### :books: (Refine Doc) diff --git a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts index 54152a4920..2d9808bf35 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts @@ -106,7 +106,7 @@ function enforcePrometheusNamingConvention( function valueString(value: number) { if (Number.isNaN(value)) { - return 'Nan'; + return 'NaN'; } else if (!Number.isFinite(value)) { if (value < 0) { return '-Inf'; diff --git a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts index 6c5def7bcf..5495ca0a8b 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts @@ -622,7 +622,7 @@ describe('PrometheusSerializer', () => { it('should serialize non-finite values', async () => { const serializer = new PrometheusSerializer(); const cases = [ - [NaN, 'Nan'], + [NaN, 'NaN'], [-Infinity, '-Inf'], [+Infinity, '+Inf'], ] as [number, string][];