Skip to content

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

weyert
Copy link
Contributor

@weyert weyert commented Apr 2, 2025

Which problem is this PR solving?

Migrated away from using process.env to use the getStringFromEnv-function

Fixes #5562

Short description of the changes

Replaced the usage of process.env with the built-in getEnv utility functions

Type of change

  • Bug fix (non-breaking change which fixes an issue)

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

  • Test A

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

weyert added 3 commits April 2, 2025 17:07
Migrated away from using `process.env` to use the `getStringFromEnv`-function

Signed-off-by: Weyert de Boer <wdb@innerfuse.biz>
…tFromEnv`-functions

Signed-off-by: Weyert de Boer <wdb@innerfuse.biz>
Copy link

codecov bot commented Apr 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.02%. Comparing base (b0e4e4f) to head (ead56a6).

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     
Files with missing lines Coverage Δ
...base/src/configuration/shared-env-configuration.ts 96.42% <100.00%> (-3.58%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@weyert weyert changed the title fix: use get*FromEnv() for otlp exporter config refactor: use get*FromEnv() for otlp exporter config Apr 6, 2025
Signed-off-by: Weyert de Boer <wdb@innerfuse.biz>
@@ -78,11 +78,11 @@ 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)'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would appreciate some guidance for the maintainer how to go about this. The getStringFromEnv -function itself outputs this message and then shared-env-configuration.ts tries to log a warning in one situation too. For now I have updated the check to use the warning created by the getStringFromEnv -function.

I am not sure if that is what we want, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming that if you didn't make this update, the test was failing. Is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maryliag Yes, that's correct. My understanding is because of the warn call in get*FromEnv() function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct on what is happening. And it is fine, IMO. The specific format of warning messages are not a promised interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to Trent message

@weyert weyert marked this pull request as ready for review April 6, 2025 14:39
@weyert weyert requested a review from a team as a code owner April 6, 2025 14:39
@maryliag maryliag changed the title refactor: use get*FromEnv() for otlp exporter config refactor(otlp-exporter-base): use get*FromEnv() for otlp exporter config Apr 7, 2025
if (Number.isFinite(definedTimeout) && definedTimeout > 0) {
return definedTimeout;
const envTimeout = getNumberFromEnv(timeoutEnvVar);
if (envTimeout) {
Copy link
Contributor

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.

Suggested change
if (envTimeout) {
if (envTimeout !== undefined) {

Comment on lines +50 to 53
const compression = getStringFromEnv(compressionEnvVar)?.trim();
if (compression === '') {
return undefined;
}
Copy link
Contributor

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.

Suggested change
const compression = getStringFromEnv(compressionEnvVar)?.trim();
if (compression === '') {
return undefined;
}
const compression = getStringFromEnv(compressionEnvVar);

@@ -78,11 +78,11 @@ 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)'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct on what is happening. And it is fine, IMO. The specific format of warning messages are not a promised interface.

@@ -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`
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[contribfest] use new get*FromEnv() functions in OTLP exporter shared env var configuration
3 participants