-
Notifications
You must be signed in to change notification settings - Fork 899
refactor(otlp-exporter-base): use get*FromEnv() for otlp exporter config #5583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
refactor(otlp-exporter-base): use get*FromEnv() for otlp exporter config #5583
Conversation
Migrated away from using `process.env` to use the `getStringFromEnv`-function Signed-off-by: Weyert de Boer <[email protected]>
…tFromEnv`-functions Signed-off-by: Weyert de Boer <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5583 +/- ##
==========================================
- Coverage 95.03% 95.02% -0.02%
==========================================
Files 310 310
Lines 7952 7952
Branches 1605 1605
==========================================
- Hits 7557 7556 -1
- Misses 395 396 +1
🚀 New features to boost your workflow:
|
Signed-off-by: Weyert de Boer <[email protected]>
...imental/packages/otlp-exporter-base/test/node/configuration/shared-env-configuration.test.ts
Show resolved
Hide resolved
if (Number.isFinite(definedTimeout) && definedTimeout > 0) { | ||
return definedTimeout; | ||
const envTimeout = getNumberFromEnv(timeoutEnvVar); | ||
if (envTimeout) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this will accidentally not go through this if-statement if the envvar value is '0'
:
> process.env.FOO
'0'
> core.getNumberFromEnv('FOO')
0
> delete process.env.FOO
true
> process.env.FOO
undefined
> core.getNumberFromEnv('FOO')
undefined
The side-effect will be that OTEL_EXPORTER_OTLP_METRICS_TIMEOUT=0
will not result in the diag.warn(...)
message.
if (envTimeout) { | |
if (envTimeout !== undefined) { |
const compression = getStringFromEnv(compressionEnvVar)?.trim(); | ||
if (compression === '') { | ||
return undefined; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified. getStringFromEnv
will handle trimming and returning undefined
if the envvar is an empty string.
const compression = getStringFromEnv(compressionEnvVar)?.trim(); | |
if (compression === '') { | |
return undefined; | |
} | |
const compression = getStringFromEnv(compressionEnvVar); |
...imental/packages/otlp-exporter-base/test/node/configuration/shared-env-configuration.test.ts
Show resolved
Hide resolved
@@ -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)' | |||
`Unknown value '-Infinitiy' for OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, expected a number, using defaults` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised at this one. I would expect getNumberFromEnv
to pass on '-Infinity'
:
> process.env.FOO = '-Infinity'
'-Infinity'
> core.getNumberFromEnv('FOO')
-Infinity
Co-authored-by: Trent Mick <[email protected]>
Which problem is this PR solving?
Migrated away from using
process.env
to use thegetStringFromEnv
-functionFixes #5562
Short description of the changes
Replaced the usage of
process.env
with the built-in getEnv utility functionsType of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: