Skip to content

Commit 814b582

Browse files
authored
Truetime.now issue (#340)
* Bumping up dependencies * Updating notice files * Falling back to system time when truetime.now throws error.
1 parent acc6e6d commit 814b582

File tree

7 files changed

+31
-14
lines changed

7 files changed

+31
-14
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dependencies.hash=6AB0841BC9D2A49600D8C01CB49722DD
1+
dependencies.hash=DE88CF9A9513ADACB700200CCAF64110
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dependencies.hash=4335DC6BB998D19BBBD590A9B2803A50
1+
dependencies.hash=3E9E21CD8D354DEE5A74726273DC2F2D
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dependencies.hash=A0177AAB7C169836786E530C6453B8A1
1+
dependencies.hash=116B097450368CFACC99BF27198E0C94

android-sdk/src/main/java/co/elastic/apm/android/sdk/internal/opentelemetry/tools/ElasticClock.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ public ElasticClock(TrueTimeWrapper trueTimeWrapper) {
4545
public long now() {
4646
if (trueTimeWrapper.isInitialized()) {
4747
Elog.getLogger().debug("Returning true time");
48-
return TimeUnit.MILLISECONDS.toNanos(trueTimeWrapper.now().getTime());
48+
try {
49+
return TimeUnit.MILLISECONDS.toNanos(trueTimeWrapper.now().getTime());
50+
} catch (Throwable t) {
51+
trueTimeWrapper.clearCachedInfo();
52+
Elog.getLogger().error("Could not get true time", t);
53+
}
4954
}
5055
Elog.getLogger().debug("Returning system time");
5156
return TimeUnit.MILLISECONDS.toNanos(systemTimeProvider.getCurrentTimeMillis());

android-sdk/src/test/java/co/elastic/apm/android/sdk/internal/otel/ElasticClockTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import static org.junit.Assert.assertEquals;
2222
import static org.mockito.Mockito.doReturn;
23+
import static org.mockito.Mockito.doThrow;
2324
import static org.mockito.Mockito.verify;
2425

2526
import org.junit.Before;
@@ -31,9 +32,9 @@
3132
import java.util.Date;
3233
import java.util.concurrent.TimeUnit;
3334

35+
import co.elastic.apm.android.sdk.internal.opentelemetry.tools.ElasticClock;
3436
import co.elastic.apm.android.sdk.internal.time.SystemTimeProvider;
3537
import co.elastic.apm.android.sdk.internal.time.ntp.TrueTimeWrapper;
36-
import co.elastic.apm.android.sdk.internal.opentelemetry.tools.ElasticClock;
3738
import co.elastic.apm.android.sdk.testutils.BaseTest;
3839

3940
@RunWith(MockitoJUnitRunner.class)
@@ -61,7 +62,7 @@ public void whenProvidingNanoTime_returnSystemNanoTime() {
6162
}
6263

6364
@Test
64-
public void whenProvidingNow_withNoTrueTimeAvailable_returnSystemCurrentTimeInNanos() {
65+
public void whenProvidingNow_withTrueTimeNotInitialized_returnSystemCurrentTimeInNanos() {
6566
long systemTimeMillis = 12345;
6667
long systemTimeNanos = TimeUnit.MILLISECONDS.toNanos(systemTimeMillis);
6768
doReturn(systemTimeMillis).when(systemTimeProvider).getCurrentTimeMillis();
@@ -70,6 +71,17 @@ public void whenProvidingNow_withNoTrueTimeAvailable_returnSystemCurrentTimeInNa
7071
assertEquals(systemTimeNanos, elasticClock.now());
7172
}
7273

74+
@Test
75+
public void whenProvidingNow_withNoTrueTimeAvailable_returnSystemCurrentTimeInNanos() {
76+
long systemTimeMillis = 12345;
77+
long systemTimeNanos = TimeUnit.MILLISECONDS.toNanos(systemTimeMillis);
78+
doReturn(systemTimeMillis).when(systemTimeProvider).getCurrentTimeMillis();
79+
doReturn(true).when(trueTimeWrapper).isInitialized();
80+
doThrow(IllegalStateException.class).when(trueTimeWrapper).now();
81+
82+
assertEquals(systemTimeNanos, elasticClock.now());
83+
}
84+
7385
@Test
7486
public void whenProvidingNow_withTrueTimeAvailable_returnTrueTimeInNanos() {
7587
long trueTimeMillis = 12345;

gradle/libs.versions.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[versions]
22
opentelemetry-android = "0.5.0-alpha"
3-
opentelemetry = "1.37.0"
4-
opentelemetry-alpha = "1.37.0-alpha"
5-
opentelemetry-semconv = "1.25.0-alpha"
6-
opentelemetry-contrib = "1.35.0-alpha"
3+
opentelemetry = "1.40.0"
4+
opentelemetry-alpha = "1.40.0-alpha"
5+
opentelemetry-semconv = "1.26.0-alpha"
6+
opentelemetry-contrib = "1.37.0-alpha"
77
mockito = "4.11.0"
8-
byteBuddy = "1.14.17"
8+
byteBuddy = "1.14.18"
99
okhttp = "4.12.0"
10-
kotlin = "1.9.22"
10+
kotlin = "1.9.23"
1111
google-autoService = "1.1.1"
1212

1313
[libraries]

manual_licenses_map.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
net.bytebuddy:byte-buddy:1.14.17|apache_v2
2-
net.bytebuddy:byte-buddy-gradle-plugin:1.14.17|apache_v2
1+
net.bytebuddy:byte-buddy:1.14.18|apache_v2
2+
net.bytebuddy:byte-buddy-gradle-plugin:1.14.18|apache_v2
33
org.slf4j:slf4j-api:2.0.0|mit
44
com.squareup.okhttp3:okhttp:3.11.0|apache_v2
55
com.github.instacart.truetime-android:library:3.5|apache_v2

0 commit comments

Comments
 (0)