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

feat: anchored clock

Open dyladan opened this issue 1 year ago • 1 comments

Introduce an anchored clock which is resistant to time drift. Create a single anchored clock instance per local trace and store the anchored clocks in a weak map on the tracer to ensure they don't memory leak.

dyladan avatar Aug 01 '22 19:08 dyladan

Codecov Report

Merging #3134 (7f056da) into main (32cb123) will increase coverage by 0.00%. The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3134   +/-   ##
=======================================
  Coverage   93.28%   93.28%           
=======================================
  Files         201      202    +1     
  Lines        6579     6599   +20     
  Branches     1379     1384    +5     
=======================================
+ Hits         6137     6156   +19     
- Misses        442      443    +1     
Impacted Files Coverage Δ
...es/opentelemetry-core/src/common/anchored-clock.ts 100.00% <100.00%> (ø)
packages/opentelemetry-sdk-trace-base/src/Span.ts 99.19% <100.00%> (+<0.01%) :arrow_up:
...ackages/opentelemetry-sdk-trace-base/src/Tracer.ts 98.68% <100.00%> (+0.22%) :arrow_up:
...-trace-base/src/platform/node/RandomIdGenerator.ts 87.50% <0.00%> (-6.25%) :arrow_down:

codecov[bot] avatar Aug 01 '22 19:08 codecov[bot]

Seems like browser tests are unhappy:

ERROR in ./test/common/anchored-clock.test.ts
Module not found: Error: Can't resolve 'perf_hooks' in '/__w/opentelemetry-js/opentelemetry-js/packages/opentelemetry-core/test/common'
 @ ./test/common/anchored-clock.test.ts 19:21-42

Flarna avatar Sep 09 '22 06:09 Flarna

Seems like browser tests are unhappy:

ERROR in ./test/common/anchored-clock.test.ts
Module not found: Error: Can't resolve 'perf_hooks' in '/__w/opentelemetry-js/opentelemetry-js/packages/opentelemetry-core/test/common'
 @ ./test/common/anchored-clock.test.ts 19:21-42

and thats why we have them

dyladan avatar Sep 09 '22 20:09 dyladan

i am getting these errors Inconsistent start and end time, startTime > endTime [ 1663917517, 902433872 ] [ 1663917517, 901867218 ]

itai-codefresh avatar Sep 23 '22 07:09 itai-codefresh

Hi @itai-codefresh, thanks for reporting this. Do you have a way to reproduce this issue? :thinking: If so, could you please open a bug ticket so that we can take a look? :slightly_smiling_face:

pichlermarc avatar Sep 23 '22 08:09 pichlermarc

At least instrumentation express provides a timestamp to span.end() but not to startSpan(). Therefore two different time sources are used resulting in undefined results.

See https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1209 and https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1193

Flarna avatar Sep 28 '22 09:09 Flarna