Skip to content

Conversation

@Dav1dde
Copy link
Member

@Dav1dde Dav1dde commented Jul 30, 2025

This also deals with floating point sub-microsecond inaccuracies on parsing, instead of only on serialization.

Logs access the nanoseconds of the extracted timestamp and persist these into the payload, this leads to subtle inaccuracies because it never goes through the floating point serialization code which would deal with these inaccuracies.

As it turns out this also applies to calculated span durations which were off.

Instead account for these inaccuracies when parsing from a float, but also when serializing, as the timestamp may have been constructed from something with 'perfect' accuracy.

Also fixes this:
image

@Dav1dde Dav1dde requested a review from a team as a code owner July 30, 2025 09:03
@Dav1dde Dav1dde force-pushed the dav1d/ts-log-nano-inacc branch 2 times, most recently from f117a67 to ae0f0cb Compare July 30, 2025 09:04
return {
"sentry.observed_timestamp_nanos": {
"stringValue": time_within(ts, expect_resolution="ns", precision="s")
"stringValue": time_within(ts, expect_resolution="ns")
Copy link
Member Author

@Dav1dde Dav1dde Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was incorrect, before, the observed_timestamp_nanos is set from the received timestamp, which is derived from the current time in Relay, not an input.

Fixed here because I used these tests to verify the flakiness is gone (which was observable under repeated execution).

@Dav1dde Dav1dde self-assigned this Jul 30, 2025
cursor[bot]

This comment was marked as outdated.

@Dav1dde Dav1dde marked this pull request as draft July 30, 2025 09:41
@Dav1dde Dav1dde force-pushed the dav1d/ts-log-nano-inacc branch from 7acf98c to d153981 Compare July 30, 2025 11:25
@Dav1dde Dav1dde marked this pull request as ready for review July 30, 2025 11:25
@Dav1dde Dav1dde force-pushed the dav1d/ts-log-nano-inacc branch from d153981 to 3597ba3 Compare July 30, 2025 11:26
cursor[bot]

This comment was marked as outdated.

@Dav1dde Dav1dde force-pushed the dav1d/ts-log-nano-inacc branch from 12cf442 to 9452280 Compare July 30, 2025 12:00
cursor[bot]

This comment was marked as outdated.

@Dav1dde Dav1dde force-pushed the dav1d/ts-log-nano-inacc branch from 9452280 to 32ba503 Compare July 30, 2025 12:02
@Dav1dde Dav1dde requested a review from loewenheim July 30, 2025 12:02
Comment on lines +1038 to +1063
fn test_timestamp_to_datetime() {
assert_eq!(timestamp_to_datetime(0.), Utc.timestamp_opt(0, 0));
assert_eq!(timestamp_to_datetime(1000.), Utc.timestamp_opt(1000, 0));
assert_eq!(timestamp_to_datetime(-1000.), Utc.timestamp_opt(-1000, 0));
assert_eq!(
timestamp_to_datetime(1.234_567),
Utc.timestamp_opt(1, 234_567_000)
);
assert_eq!(timestamp_to_datetime(2.999_999_51), Utc.timestamp_opt(3, 0));
assert_eq!(
timestamp_to_datetime(2.999_999_45),
Utc.timestamp_opt(2, 999_999_000)
);
assert_eq!(
timestamp_to_datetime(-0.000_001),
Utc.timestamp_opt(-1, 999_999_000)
);
assert_eq!(
timestamp_to_datetime(-3.000_000_49),
Utc.timestamp_opt(-3, 0)
);
assert_eq!(
timestamp_to_datetime(-3.000_000_51),
Utc.timestamp_opt(-4, 999_999_000)
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@Dav1dde Dav1dde added this pull request to the merge queue Jul 30, 2025
Merged via the queue into master with commit 1bdc463 Jul 30, 2025
29 checks passed
@Dav1dde Dav1dde deleted the dav1d/ts-log-nano-inacc branch July 30, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants