Skip to content

Commit

Permalink
refactor(otlp-exporter-base): remove unnecessary isNaN() checks (#5374
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cjihrig authored Jan 27, 2025
1 parent f927e82 commit 3e013cf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ All notable changes to experimental packages in this project will be documented

### :house: (Internal)

* refactor(otlp-exporter-base): remove unnecessary isNaN() checks [#5374](https://github.com/open-telemetry/opentelemetry-js/pull/5374) @cjihrig

## 0.57.0

### :rocket: (Enhancement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ export interface OtlpSharedConfiguration {
}

export function validateTimeoutMillis(timeoutMillis: number) {
if (
!Number.isNaN(timeoutMillis) &&
Number.isFinite(timeoutMillis) &&
timeoutMillis > 0
) {
if (Number.isFinite(timeoutMillis) && timeoutMillis > 0) {
return timeoutMillis;
}
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ function parseAndValidateTimeoutFromEnv(
const envTimeout = process.env[timeoutEnvVar]?.trim();
if (envTimeout != null && envTimeout !== '') {
const definedTimeout = Number(envTimeout);
if (
!Number.isNaN(definedTimeout) &&
Number.isFinite(definedTimeout) &&
definedTimeout > 0
) {
if (Number.isFinite(definedTimeout) && definedTimeout > 0) {
return definedTimeout;
}
diag.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
mergeOtlpSharedConfigurationWithDefaults,
OtlpSharedConfiguration,
} from '../../../src';
import { validateTimeoutMillis } from '../../../src/configuration/shared-configuration';

export function testSharedConfigBehavior<T extends OtlpSharedConfiguration>(
sut: (
Expand Down Expand Up @@ -134,3 +135,15 @@ describe('mergeOtlpSharedConfigurationWithDefaults', function () {
concurrencyLimit: 2,
});
});

describe('validateTimeoutMillis', function () {
it('throws if timeout is not a positive number', () => {
const values = [null, '1', true, NaN, Infinity, -Infinity, -1, 0];

for (let i = 0; i < values.length; ++i) {
assert.throws(() => {
validateTimeoutMillis(values[i] as any);
}, /Configuration: timeoutMillis is invalid/);
}
});
});

0 comments on commit 3e013cf

Please sign in to comment.