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

Distributed tracing: Fixing clock skew #714

Closed
Acren opened this issue Dec 16, 2024 · 5 comments · Fixed by #715
Closed

Distributed tracing: Fixing clock skew #714

Acren opened this issue Dec 16, 2024 · 5 comments · Fixed by #715

Comments

@Acren
Copy link

Acren commented Dec 16, 2024

Hello,

We are using the new distributed tracing in the UE SDK with our other services running Sentry.
This is working well other than the clock skew.

The documentation notes:

Clock Skew
Collecting transactions from multiple machines may result in clock skew, where timestamps in one transaction don't align with timestamps in another. To reduce this, use Network Time Protocol (NTP) or your cloud provider's clock synchronization services.

So, following this, if we use an NTP server as suggested to calculate the corrected local time, how do we then use the corrected time with the Sentry SDK to fix the transaction and span timestamps?

Much thanks,
Sam

@tustanivsky
Copy link
Collaborator

The UE SDK doesn't currently provide an interface to override transaction and span timestamps. However, the underlying sentry-native library introduced APIs allowing to set custom timestamps in a recent update which might be worth exploring (see PR #1093 for details and issue #941 for additional context).

Alternatively, you can try using lower-level calls to the native SDK to modify transaction/span objects directly like this:

uint64_t correctedTimestamp = /* your corrected UNIX timestamp */;
sentry_value_set_by_key(transaction, "start_timestamp", 
    sentry__value_new_string_owned(sentry__usec_time_to_iso8601(correctedTimestamp)));

@Acren
Copy link
Author

Acren commented Dec 17, 2024

Thanks for the response. What's the correct way to call sentry_value_set_by_key via the UE SDK in this case? As far as I can see there doesn't seem to be a way to access the native transaction object from a USentryTransaction or ISentryTransaction, unless I'm mistaken.
Can this be done with SetData or SetTag?

@tustanivsky
Copy link
Collaborator

However, the underlying sentry-native library introduced APIs allowing to set custom timestamps in a recent update which might be worth exploring (see getsentry/sentry-native#1093 for details and getsentry/sentry-native#941 for additional context).

@Acren I've opened a PR (#715) that adds these new APIs to Unreal plugin. Currently, their usage is limited to Windows and Linux so that's something to keep in mind if you're considering to support Apple/Android. You can give it a try by downloading the updated package from our GitHub CI.

What's the correct way to call sentry_value_set_by_key via the UE SDK in this case?

You can't access native transaction objects directly. Instead, you'll need to add timestamp setter to SentrySubsystemDesktop and expose it via ISentryTransaction/USentryTransaction to ensure its value can be passed from Unreal to the native SDK layer. The linked PR might serve as a helpful reference for implementing this.

Can this be done with SetData or SetTag?

No, Sentry backend treats tags and extra data differently so you won't be able to achieve the exact same result by using those.

@Acren
Copy link
Author

Acren commented Dec 18, 2024

Thanks a lot for that, I tried that version and it works perfectly.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 18, 2024
@tustanivsky
Copy link
Collaborator

Awesome, thank you for confirming it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Archived in project
2 participants