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

fix(core): fix precision loss in numberToHrtime

Open legendecas opened this issue 2 years ago • 1 comments
trafficstars

Which problem is this PR solving?

Fixes https://github.com/open-telemetry/opentelemetry-js/issues/3459

Avoid unnecessary stringify of number values as the precision loss is inevitable with toFixed too. This also fixes precision loss on numbers without fractional parts.

Type of change

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

How Has This Been Tested?

  • [x] Fix precision loss: should convert Date hrTime

Checklist:

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

legendecas avatar Dec 09 '22 02:12 legendecas

Codecov Report

Merging #3480 (33d7f73) into main (3fd6fb8) will increase coverage by 0.06%. The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3480      +/-   ##
==========================================
+ Coverage   93.70%   93.77%   +0.06%     
==========================================
  Files         247      249       +2     
  Lines        7439     7612     +173     
  Branches     1554     1587      +33     
==========================================
+ Hits         6971     7138     +167     
- Misses        468      474       +6     
Impacted Files Coverage Δ
packages/opentelemetry-core/src/common/time.ts 95.58% <100.00%> (+0.13%) :arrow_up:
...-trace-base/src/platform/node/RandomIdGenerator.ts 87.50% <0.00%> (-6.25%) :arrow_down:
...s/opentelemetry-instrumentation-fetch/src/fetch.ts 97.00% <0.00%> (ø)
...-instrumentation-fetch/src/enums/AttributeNames.ts 100.00% <0.00%> (ø)

codecov[bot] avatar Dec 09 '22 02:12 codecov[bot]