opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

Feat get env memo

Open RazGvili opened this issue 2 years ago • 2 comments
trafficstars

Which problem is this PR solving?

  1. node getEnv() is invoked every time an env var is accessed. This causes parsing of all DEFAULT_ENVIRONMENT every invocation.
  2. HOSTNAME was set by os.hostname() and then immediately overwritten by the DEFAULT_ENVIRONMENT.

Fixes # (issue)

  1. Use module-level cache for the env.
  2. Remove the setting of HOSTNAME via os.hostname().

Short description of the changes

getEnv() will use module-level cache. calculateEnv() is separated from getEnv() for better separation and for testing purposes. os.hostname() removed from getEnv().

Type of change

  • [ ] New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • [ ] First(no cache) and second(with cache) invocation results are using the same object.

RazGvili avatar Dec 18 '22 16:12 RazGvili

Thank you for your work on this!

legendecas avatar Dec 20 '22 03:12 legendecas

Codecov Report

Merging #3496 (6a52c25) into main (47444f2) will increase coverage by 0.01%. The diff coverage is 100.00%.

:exclamation: Current head 6a52c25 differs from pull request most recent head 1b3db7e. Consider uploading reports for the commit 1b3db7e to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3496      +/-   ##
==========================================
+ Coverage   94.01%   94.03%   +0.01%     
==========================================
  Files         268      268              
  Lines        7920     7927       +7     
  Branches     1641     1642       +1     
==========================================
+ Hits         7446     7454       +8     
+ Misses        474      473       -1     
Impacted Files Coverage Δ
...pentelemetry-core/src/platform/node/environment.ts 100.00% <100.00%> (ø)
...-trace-base/src/platform/node/RandomIdGenerator.ts 93.75% <0.00%> (+6.25%) :arrow_up:

codecov[bot] avatar Dec 20 '22 03:12 codecov[bot]

@RazGvili was excited to see this but the tests weren't passing and i haven't seen anything in a while. are you still working on this?

dyladan avatar Jan 27 '23 21:01 dyladan

@dyladan I think I can finish it this week.

The env memo requires a clear afterEach test, for all the repos using the getEnv.

RazGvili avatar Jan 28 '23 10:01 RazGvili

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] avatar Jul 17 '23 06:07 github-actions[bot]