Skip to content
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

Add a way to compensate for clock skew #1728

Open
dobesv opened this issue Dec 7, 2020 · 5 comments
Open

Add a way to compensate for clock skew #1728

dobesv opened this issue Dec 7, 2020 · 5 comments

Comments

@dobesv
Copy link
Contributor

dobesv commented Dec 7, 2020

If the system clock on computer is out of sync from others it can cause problems. This is most likely to be an issue in the browser, where users are less likely to sync with time servers.

Our browser app already has a system to calculate clock skew between client and server using an NTP based system, so simply having an API to report clock skew in milliseconds to the OpenTelemetry client library would work for us.

Other more flexible solutions could work as well. e.g. see #1652

Note however that we do not know the clock skew at the time the telemetry library starts, and the clock skew can vary if the user adjusts their clock or whatever. So we periodically re-calculate clock skew and would want to periodically update the clock skew used in by opentelemetry.

@dobesv
Copy link
Contributor Author

dobesv commented Dec 7, 2020

I guess option might be to modify /~https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-core/src/common/time.ts along these lines:

// Offset to add to performance.timeOrigin to get a network time (e.g. correct for clock skew)
let timeOriginOffset: number = 0; 

/**
 * Set the time origin offset to the number of milliseconds difference between the network
 * clock and the local system clock.  This will be added to the timestamps created by
 * opentelemetry to adjust for clock skew between systems.
 *
 * As for how to calculate clock skew, you can implement a version of NTP to calculate the
 * current network clock time and calling setTimeOriginOffset(networkTime - Date.now()). 
 */
export function setTimeOriginOffset(offset: number) {  timeOriginOffset = offset; }

function getTimeOrigin(): number {
  let timeOrigin = performance.timeOrigin;
  if (typeof timeOrigin !== 'number') {
    const perf: TimeOriginLegacy = (performance as unknown) as TimeOriginLegacy;
    timeOrigin = perf.timing && perf.timing.fetchStart;
  }
  return timeOrigin + timeOriginOffset;
}

@mwear
Copy link
Member

mwear commented Jan 5, 2021

Similar discussions have come up here: #852.

@pranshuchittora
Copy link

Facing same issue while instrumenting my FE app with SigNoz.io.
Looks like clock skew is happening only with Chromium based browsers (and not always).

Screenshot 2022-04-07 at 15 51 47

@dyladan
Copy link
Member

dyladan commented Apr 7, 2022

Facing same issue while instrumenting my FE app with SigNoz.io. Looks like clock skew is happening only with Chromium based browsers (and not always).

Screenshot 2022-04-07 at 15 51 47

Looks like you're running into #852 which is slightly different than this issue.

@martinkuba
Copy link
Contributor

Related issue (not specific to JS)
open-telemetry/oteps#154

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants