-
-
Notifications
You must be signed in to change notification settings - Fork 461
Description
Problem Statement
Spans are currently only ms precision but appear to be more precise due to being converted to a double. In the UI it looks like start_timestamp of a span is μs. This is caused by a number of things.
- Relay strips
nsfrom the timestamp and usesμsinstead (see https://github.com/getsentry/relay/blob/adbf8ff387285935553354c48ef04798c9a1c1ae/relay-general/src/protocol/types.rs#L965-L983). - The Java SDK records the start timestamp as
Date, then retrieves the millis viagetTime()and then divides by1000(see)this.startTimestamp = DateUtils.dateToSeconds(span.getStartTimestamp());
Solution Brainstorm
We could create a DateProvider interface which has a now() method that returns the current timestamp as SentryDate. Then there could by different implementations:
- For older versions there could be one that keeps the current
Date+System.nanoTime - For Java 9+ and Android API 26+ we could use
Instant
We could then allow passing in SentryDate when starting a span or when calling finish. For users who want to supply their own timestamps with high precision we could offer something like a SentryDoubleDate that just holds a double.
The SentryDate should also have a Double diff(SentryDate date) method that can calculate the difference using internals like the separate System.nanoTime that was collected.