You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The browser implementation of performance.now() can return identical values if two calls to performance.now() occur in close enough succession. When a call performance.now() is made to assign a value to a span's start or end time prior to the approprate startSpan or span.end() call, Span._getTime() can incorrectly assume that the time a real number containing the quantity of milliseconds since the epoch.
As a result, an error about an inconsistent timespan is returned:
Inconsistent start and end time, startTime > endTime. Setting span duration to 0ms. (2) [1730741930, 287940097] (2) [17, 220185000]
it has also been observed that when this check fails at startSpan (or startActiveSpan) the resulting span can have a duration much longer than actual.
Instead of this check:
if(typeofinp==='number'&&inp<otperformance.now()){// must be a performance timestamp// apply correction and convert to hrtimereturnhrTime(inp+this._performanceOffset);}if(typeofinp==='number'){returnmillisToHrTime(inp);}// omitted for clarity}
This will allow situations where two calls to otperformance.now() happen in quick succession in the browser to correctly process the time.
(tested in Google Chrome Version 130.0.6723.91 (Official Build) (64-bit) on ubuntu 22.04)
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport" content="width=device-width, initial-scale=1.0"><title>Performance Test</title></head><body><h1>Performance.now() Test</h1><buttonid="testButton">Run Test</button><pid="result"></p><script>document.getElementById('testButton').addEventListener('click',function(){letsameValueCount=0;letpreviousTime=performance.now();for(leti=0;i<100000;i++){constcurrentTime=performance.now();if(currentTime===previousTime){sameValueCount++;}previousTime=currentTime;}document.getElementById('result').textContent=`Number of times two successive calls to performance.now() had the same value: ${sameValueCount}`;});</script></body></html>
A similar node script behaves as expected with performance.now() returning monotonically increasing values.
(tested with node: v18.17.1)
const{ performance }=require('perf_hooks');letsameValueCount=0;letpreviousTime=performance.now();for(leti=0;i<100000;i++){constcurrentTime=performance.now();if(currentTime===previousTime){sameValueCount++;}previousTime=currentTime;}console.log(`Number of times two successive calls to performance.now() had the same value: ${sameValueCount}`);
The text was updated successfully, but these errors were encountered:
opentelemetry-js/packages/opentelemetry-sdk-trace-base/src/Span.ts
Line 283 in ce5bbfb
The browser implementation of performance.now() can return identical values if two calls to performance.now() occur in close enough succession. When a call performance.now() is made to assign a value to a span's start or end time prior to the approprate startSpan or span.end() call, Span._getTime() can incorrectly assume that the time a real number containing the quantity of milliseconds since the epoch.
As a result, an error about an inconsistent timespan is returned:
it has also been observed that when this check fails at startSpan (or startActiveSpan) the resulting span can have a duration much longer than actual.
Instead of this check:
the check should be:
This will allow situations where two calls to otperformance.now() happen in quick succession in the browser to correctly process the time.
(tested in Google Chrome Version 130.0.6723.91 (Official Build) (64-bit) on ubuntu 22.04)
A similar node script behaves as expected with performance.now() returning monotonically increasing values.
(tested with node: v18.17.1)
The text was updated successfully, but these errors were encountered: