Skip to content

Commit

Permalink
refactor(exporter-prometheus): remove unnecessary isNaN() check (#5377
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cjihrig authored Jan 27, 2025
1 parent c43f172 commit 321c31f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ All notable changes to experimental packages in this project will be documented

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

## 0.57.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,12 @@ function enforcePrometheusNamingConvention(
}

function valueString(value: number) {
if (Number.isNaN(value)) {
return 'NaN';
} else if (!Number.isFinite(value)) {
if (value < 0) {
return '-Inf';
} else {
return '+Inf';
}
if (value === Infinity) {
return '+Inf';
} else if (value === -Infinity) {
return '-Inf';
} else {
// Handle finite numbers and NaN.
return `${value}`;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ describe('PrometheusSerializer', () => {
it('should serialize non-finite values', async () => {
const serializer = new PrometheusSerializer();
const cases = [
[NaN, 'NaN'],
[-Infinity, '-Inf'],
[+Infinity, '+Inf'],
] as [number, string][];
Expand Down

0 comments on commit 321c31f

Please sign in to comment.