refactor(otlp-exporter-base): use get*FromEnv() for otlp exporter config (#5583)
Signed-off-by: Weyert de Boer <wdb@innerfuse.biz> Co-authored-by: Trent Mick <trentm@gmail.com> Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
This commit is contained in:
parent
2d3760898c
commit
a9fc9b8610
|
|
@ -16,6 +16,8 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
|
|||
|
||||
### :house: Internal
|
||||
|
||||
* refactor(otlp-exporter-base): use get*FromEnv() for otlp exporter config. [#5583](https://github.com/open-telemetry/opentelemetry-js/issues/5583) @weyert
|
||||
|
||||
## 0.205.0
|
||||
|
||||
### :boom: Breaking Changes
|
||||
|
|
|
|||
|
|
@ -13,22 +13,23 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { getNumberFromEnv, getStringFromEnv } from '@opentelemetry/core';
|
||||
import { OtlpSharedConfiguration } from './shared-configuration';
|
||||
import { diag } from '@opentelemetry/api';
|
||||
|
||||
function parseAndValidateTimeoutFromEnv(
|
||||
timeoutEnvVar: string
|
||||
): number | undefined {
|
||||
const envTimeout = process.env[timeoutEnvVar]?.trim();
|
||||
if (envTimeout != null && envTimeout !== '') {
|
||||
const definedTimeout = Number(envTimeout);
|
||||
if (Number.isFinite(definedTimeout) && definedTimeout > 0) {
|
||||
return definedTimeout;
|
||||
const envTimeout = getNumberFromEnv(timeoutEnvVar);
|
||||
if (envTimeout != null) {
|
||||
if (Number.isFinite(envTimeout) && envTimeout > 0) {
|
||||
return envTimeout;
|
||||
}
|
||||
diag.warn(
|
||||
`Configuration: ${timeoutEnvVar} is invalid, expected number greater than 0 (actual: ${envTimeout})`
|
||||
);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
|
@ -46,10 +47,7 @@ function getTimeoutFromEnv(signalIdentifier: string) {
|
|||
function parseAndValidateCompressionFromEnv(
|
||||
compressionEnvVar: string
|
||||
): 'none' | 'gzip' | undefined {
|
||||
const compression = process.env[compressionEnvVar]?.trim();
|
||||
if (compression === '') {
|
||||
return undefined;
|
||||
}
|
||||
const compression = getStringFromEnv(compressionEnvVar)?.trim();
|
||||
|
||||
if (compression == null || compression === 'none' || compression === 'gzip') {
|
||||
return compression;
|
||||
|
|
|
|||
|
|
@ -78,17 +78,17 @@ export function testSharedConfigurationFromEnvironment(
|
|||
sinon.assert.calledTwice(spyLoggerWarn);
|
||||
sinon.assert.calledWithExactly(
|
||||
spyLoggerWarn,
|
||||
'Configuration: OTEL_EXPORTER_OTLP_METRICS_TIMEOUT is invalid, expected number greater than 0 (actual: NaN)'
|
||||
`Unknown value 'NaN' for OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, expected a number, using defaults`
|
||||
);
|
||||
sinon.assert.calledWithExactly(
|
||||
spyLoggerWarn,
|
||||
'Configuration: OTEL_EXPORTER_OTLP_TIMEOUT is invalid, expected number greater than 0 (actual: foo)'
|
||||
`Unknown value 'foo' for OTEL_EXPORTER_OTLP_TIMEOUT, expected a number, using defaults`
|
||||
);
|
||||
assert.strictEqual(config.timeoutMillis, undefined);
|
||||
});
|
||||
it('should not define timeoutMillis when specific and non-specific timeout values are infinite', function () {
|
||||
const spyLoggerWarn = sinon.stub(diag, 'warn');
|
||||
process.env.OTEL_EXPORTER_OTLP_METRICS_TIMEOUT = '-Infinitiy';
|
||||
process.env.OTEL_EXPORTER_OTLP_METRICS_TIMEOUT = '-Infinity';
|
||||
process.env.OTEL_EXPORTER_OTLP_TIMEOUT = 'Infinity';
|
||||
|
||||
const config = sut('METRICS');
|
||||
|
|
@ -96,7 +96,7 @@ export function testSharedConfigurationFromEnvironment(
|
|||
sinon.assert.calledTwice(spyLoggerWarn);
|
||||
sinon.assert.calledWithExactly(
|
||||
spyLoggerWarn,
|
||||
'Configuration: OTEL_EXPORTER_OTLP_METRICS_TIMEOUT is invalid, expected number greater than 0 (actual: -Infinitiy)'
|
||||
`Configuration: OTEL_EXPORTER_OTLP_TIMEOUT is invalid, expected number greater than 0 (actual: Infinity)`
|
||||
);
|
||||
sinon.assert.calledWithExactly(
|
||||
spyLoggerWarn,
|
||||
|
|
|
|||
Loading…
Reference in New Issue