Skip to content

refactor(otlp-grpc-exporter-base): use getStringFromEnv instead of process.env #5595

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 8 commits into
base: main
Choose a base branch
from

Conversation

weyert
Copy link
Contributor

@weyert weyert commented Apr 6, 2025

Which problem is this PR solving?

Updates the code to user the helper utilities to retrieve environment variable values

Fixes #5560

Short description of the changes

Switched from using process.env to using the helper utility getStringFromEnv

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

I have manually run the test script command in the package directory

Checklist:

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

Updates the code to user the helper utilities to retrieve environment variable values

fixes open-telemetry#5560

Signed-off-by: Weyert de Boer <wdb@innerfuse.biz>
@weyert weyert requested a review from a team as a code owner April 6, 2025 14:50
Signed-off-by: Weyert de Boer <wdb@innerfuse.biz>
@david-luna
Copy link
Contributor

Hi @weyert,

Thanks for your contribution. Please resolve the conflict and I think we're good to go :)

@david-luna david-luna changed the title refactor: use getStringFromEnv instead of process.env refactor(otlp-grpc-exporter-base): use getStringFromEnv instead of process.env Apr 7, 2025
Copy link

codecov bot commented Apr 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.03%. Comparing base (b0e4e4f) to head (150fe77).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5595   +/-   ##
=======================================
  Coverage   95.03%   95.03%           
=======================================
  Files         310      310           
  Lines        7952     7952           
  Branches     1605     1605           
=======================================
  Hits         7557     7557           
  Misses        395      395           
Files with missing lines Coverage Δ
...e/src/configuration/otlp-grpc-env-configuration.ts 100.00% <100.00%> (ø)
🚀 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
Copy link
Contributor Author

weyert commented Apr 9, 2025

Thanks for your contribution. Please resolve the conflict and I think we're good to go :)

@david-luna that should be resolved now

return fallbackIfNullishOrBlank(
specificEndpoint?.trim(),
nonSpecificEndpoint?.trim()
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this whole block could be simplified to (untested, and needs npm run lint:fix for formatting):

return getStringFromEnv(`OTEL_EXPORTER_OTLP_${signalIdentifier}_ENDPOINT`) ?? getStringFromEnv('OTEL_EXPORTER_OTLP_ENDPOINT');

i.e. .trim() and fallbackIfNullishOrBlank should no longer be necessary.

]
?.toLowerCase()
.trim();
)?.toLowerCase();

return (
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this whole function could be simplified to (untested):

// Use `getStringFromEnv` because any value, even if invalid, in the signal-specific envvar should win.
return (getStringFromEnv(`OTEL_EXPORTER_OTLP_${signalIdentifier}_INSECURE`)
  ? getBooleanFromEnv(`OTEL_EXPORTER_OTLP_${signalIdentifier}_INSECURE`)
  : getBooleanFromEnv('OTEL_EXPORTER_OTLP_INSECURE')
);

And the long comment on block starting with It will allow the following values as {@code true} can be removed.

const signalSpecificPath = process.env[signalSpecificEnvVar]?.trim();
const nonSignalSpecificPath = process.env[nonSignalSpecificEnvVar]?.trim();
const signalSpecificPath = getStringFromEnv(signalSpecificEnvVar);
const nonSignalSpecificPath = getStringFromEnv(nonSignalSpecificEnvVar);

const filePath = fallbackIfNullishOrBlank(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could be simplified to (untested):

const filePath = getStringFromEnv(signalSpecificEnvVar) ?? getStringFromEnv(nonSignalSpecificEnvVar);

Then, with this suggestion and those above, fallbackIfNullishOrBlank is now unused in this file and can be removed.

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 gRPC exporter env var configuration
4 participants