Skip to content

Commit 321c31f

Browse files
authored
refactor(exporter-prometheus): remove unnecessary isNaN() check (open-telemetry#5377)
1 parent c43f172 commit 321c31f

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

experimental/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ All notable changes to experimental packages in this project will be documented
3232

3333
* chore(instrumentation-grpc): remove unused findIndex() function [#5372](https://github.com/open-telemetry/opentelemetry-js/pull/5372) @cjihrig
3434
* refactor(otlp-exporter-base): remove unnecessary isNaN() checks [#5374](https://github.com/open-telemetry/opentelemetry-js/pull/5374) @cjihrig
35+
* refactor(exporter-prometheus): remove unnecessary isNaN() check [#5377](https://github.com/open-telemetry/opentelemetry-js/pull/5377) @cjihrig
3536

3637
## 0.57.0
3738

experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,12 @@ function enforcePrometheusNamingConvention(
104104
}
105105

106106
function valueString(value: number) {
107-
if (Number.isNaN(value)) {
108-
return 'NaN';
109-
} else if (!Number.isFinite(value)) {
110-
if (value < 0) {
111-
return '-Inf';
112-
} else {
113-
return '+Inf';
114-
}
107+
if (value === Infinity) {
108+
return '+Inf';
109+
} else if (value === -Infinity) {
110+
return '-Inf';
115111
} else {
112+
// Handle finite numbers and NaN.
116113
return `${value}`;
117114
}
118115
}

experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ describe('PrometheusSerializer', () => {
639639
it('should serialize non-finite values', async () => {
640640
const serializer = new PrometheusSerializer();
641641
const cases = [
642+
[NaN, 'NaN'],
642643
[-Infinity, '-Inf'],
643644
[+Infinity, '+Inf'],
644645
] as [number, string][];

0 commit comments

Comments
 (0)