Skip to content

Conversation

k-fish
Copy link
Member

@k-fish k-fish commented Mar 6, 2025

Summary

Observed time nanos should be set by the collector in OTel. In the case of Sentry the collector will always be Relay. We may want to allow passing observed time nanos in the future, but we can address that after we move to using EAP items consumers since they rely on 'received' instead of observed time.

Observed time nanos should be set by the collector in OTel. In the case of Sentry the collector will always be Relay. We may want to allow passing observed time nanos in the future, but we can address that after we move to using EAP items consumers since they rely on 'received' instead of observed time.
@k-fish k-fish requested a review from a team as a code owner March 6, 2025 17:18
Comment on lines +230 to +233
let observed_time = our_log.observed_timestamp_nanos.value().unwrap();
assert!(*observed_time > 0);
assert!(*observed_time >= before_test);
assert!(*observed_time <= after_test);
Copy link
Member Author

Choose a reason for hiding this comment

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

I looked briefly but didn't see any prior examples of mocking Utc::now(), open to suggestions here.

Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately as good as it gets, our testing capatbilities for time are really limited at the moment.

@@ -29,6 +30,10 @@ pub fn otel_to_sentry_log(otel_log: OtelLog) -> OurLog {

let mut attribute_data = Object::new();

// We ignore the passed observed time since Relay always acts as the collector in Sentry.
// We may change this in the future with forwarding Relays.
let observed_time_unix_nano = Utc::now().timestamp_nanos_opt().unwrap_or(0) as u64;
Copy link
Member

@Dav1dde Dav1dde Mar 6, 2025

Choose a reason for hiding this comment

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

What is the precision you need on this, generally we'd use UnixTimestamp::now() here, which has an as_secs(). This limits your precision to per second, but that seems like it should be good enough for the received/observed timestamp?

Feel free to add an as_nanos() to the UnixTimestamp or just doing the multiplication here.

Comment on lines +230 to +233
let observed_time = our_log.observed_timestamp_nanos.value().unwrap();
assert!(*observed_time > 0);
assert!(*observed_time >= before_test);
assert!(*observed_time <= after_test);
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately as good as it gets, our testing capatbilities for time are really limited at the moment.

Comment on lines 113 to 115
pub fn as_nanos(self) -> u64 {
self.0 * 1_000_000_000
}
Copy link
Member Author

Choose a reason for hiding this comment

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

@Dav1dde this what you had in mind? I like it on the UnixTimestamp.

@@ -77,7 +77,6 @@ def test_ourlog_extraction(
"project_id": 42,
"retention_days": 90,
"timestamp_nanos": int(start.timestamp() * 1e9),
"observed_timestamp_nanos": int(end.timestamp() * 1e9),
Copy link
Member

Choose a reason for hiding this comment

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

We have helpers for this, so you can assert timestamps in tests, e.g. time_within_delta() should work here.

These assert/time helpers have a custom eq logic implemented which allows fuzzy-ish time assertions.

Copy link
Member

Choose a reason for hiding this comment

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

Realized we don't have support for nanos, added it in #4562

Dav1dde added a commit that referenced this pull request Mar 7, 2025
For: #4559

Make millies/micros/nanos assertable with our `time_*` assertion
helpers.
@k-fish k-fish merged commit b700f16 into master Mar 7, 2025
25 checks passed
@k-fish k-fish deleted the feat/ourlogs/always-add-observed-time branch March 7, 2025 18:16
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.

2 participants