Skip to content

Commit ef1c11b

Browse files
authored
reverted app start span timestamp to SentryLongDate (#3410)
* reverted TimeSpan.getStartTimestamp to SentryLongDate, to not break hybrid sdks * fixed SpanFrameMetricsCollector.realNanos (it now checks the date type and reacts accordingly)
1 parent 8d236f4 commit ef1c11b

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/SpanFrameMetricsCollector.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package io.sentry.android.core;
22

3+
import io.sentry.DateUtils;
34
import io.sentry.IPerformanceContinuousCollector;
45
import io.sentry.ISpan;
56
import io.sentry.ITransaction;
67
import io.sentry.NoOpSpan;
78
import io.sentry.NoOpTransaction;
89
import io.sentry.SentryDate;
10+
import io.sentry.SentryLongDate;
911
import io.sentry.SentryNanotimeDate;
1012
import io.sentry.SentryTracer;
1113
import io.sentry.SpanDataConvention;
@@ -143,8 +145,6 @@ private void captureFrameMetrics(@NotNull final ISpan span) {
143145
if (spanFinishDate == null) {
144146
return;
145147
}
146-
// Note: The comparison between two values obtained by realNanos() works only if both are the
147-
// same kind of dates (both are SentryNanotimeDate or both SentryLongDate)
148148
final long spanEndNanos = realNanos(spanFinishDate);
149149

150150
final @NotNull SentryFrameMetrics frameMetrics = new SentryFrameMetrics();
@@ -308,7 +308,16 @@ private static int addPendingFrameDelay(
308308
* @return a timestamp in nano precision
309309
*/
310310
private static long realNanos(final @NotNull SentryDate date) {
311-
return date.diff(UNIX_START_DATE);
311+
// SentryNanotimeDate nanotime is based on System.nanotime(), like UNIX_START_DATE
312+
if (date instanceof SentryNanotimeDate) {
313+
return date.diff(UNIX_START_DATE);
314+
}
315+
316+
// SentryLongDate nanotime is based on current date converted to nanoseconds, which is a
317+
// different order than frames based System.nanotime(). So we have to convert the nanotime of
318+
// the SentryLongDate to a System.nanotime() compatible one.
319+
return date.diff(new SentryLongDate(DateUtils.millisToNanos(System.currentTimeMillis())))
320+
+ System.nanoTime();
312321
}
313322

314323
private static class Frame implements Comparable<Frame> {

sentry-android-core/src/main/java/io/sentry/android/core/performance/TimeSpan.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import io.sentry.DateUtils;
55
import io.sentry.SentryDate;
66
import io.sentry.SentryLongDate;
7-
import io.sentry.SentryNanotimeDate;
87
import java.util.concurrent.TimeUnit;
98
import org.jetbrains.annotations.ApiStatus;
109
import org.jetbrains.annotations.NotNull;
@@ -95,8 +94,7 @@ public long getStartTimestampMs() {
9594
*/
9695
public @Nullable SentryDate getStartTimestamp() {
9796
if (hasStarted()) {
98-
return new SentryNanotimeDate(
99-
DateUtils.nanosToDate(DateUtils.millisToNanos(getStartTimestampMs())), startSystemNanos);
97+
return new SentryLongDate(DateUtils.millisToNanos(getStartTimestampMs()));
10098
}
10199
return null;
102100
}

sentry-android-core/src/test/java/io/sentry/android/core/SpanFrameMetricsCollectorTest.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import io.sentry.ISpan
44
import io.sentry.ITransaction
55
import io.sentry.NoOpSpan
66
import io.sentry.NoOpTransaction
7-
import io.sentry.SentryLongDate
87
import io.sentry.SentryNanotimeDate
98
import io.sentry.SpanContext
109
import io.sentry.android.core.internal.util.SentryFrameMetricsCollector
@@ -53,10 +52,16 @@ class SpanFrameMetricsCollectorTest {
5352
val span = mock<ISpan>()
5453
val spanContext = SpanContext("op.fake")
5554
whenever(span.spanContext).thenReturn(spanContext)
56-
whenever(span.startDate).thenReturn(SentryLongDate(startTimeStampNanos))
55+
whenever(span.startDate).thenReturn(
56+
SentryNanotimeDate(
57+
Date(),
58+
startTimeStampNanos
59+
)
60+
)
5761
whenever(span.finishDate).thenReturn(
5862
if (endTimeStampNanos != null) {
59-
SentryLongDate(
63+
SentryNanotimeDate(
64+
Date(),
6065
endTimeStampNanos
6166
)
6267
} else {
@@ -73,10 +78,16 @@ class SpanFrameMetricsCollectorTest {
7378
val span = mock<ITransaction>()
7479
val spanContext = SpanContext("op.fake")
7580
whenever(span.spanContext).thenReturn(spanContext)
76-
whenever(span.startDate).thenReturn(SentryLongDate(startTimeStampNanos))
81+
whenever(span.startDate).thenReturn(
82+
SentryNanotimeDate(
83+
Date(),
84+
startTimeStampNanos
85+
)
86+
)
7787
whenever(span.finishDate).thenReturn(
7888
if (endTimeStampNanos != null) {
79-
SentryLongDate(
89+
SentryNanotimeDate(
90+
Date(),
8091
endTimeStampNanos
8192
)
8293
} else {

0 commit comments

Comments
 (0)