Skip to content

Commit

Permalink
Merge 663d6aa into 7e57220
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn authored Oct 2, 2024
2 parents 7e57220 + 663d6aa commit b464cc6
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- For example, (this is already a default behavior) to redact all `TextView`s and their subclasses (`RadioButton`, `EditText`, etc.): `options.experimental.sessionReplay.addRedactViewClass("android.widget.TextView")`
- If you're using code obfuscation, adjust your proguard-rules accordingly, so your custom view class name is not minified
- Fix ensure Application Context is used even when SDK is initialized via Activity Context ([#3669](https://github.com/getsentry/sentry-java/pull/3669))
- Fix potential ANRs due to `Calendar.getInstance` usage in Breadcrumbs constructor ([#3736](https://github.com/getsentry/sentry-java/pull/3736))

*Breaking changes*:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public open class DefaultReplayBreadcrumbConverter : ReplayBreadcrumbConverter {
}
return if (!breadcrumbCategory.isNullOrEmpty()) {
RRWebBreadcrumbEvent().apply {
timestamp = breadcrumb.timestamp.time
breadcrumbTimestamp = breadcrumb.timestamp.time / 1000.0
timestamp = breadcrumb.timestampMs
breadcrumbTimestamp = breadcrumb.timestampMs / 1000.0
breadcrumbType = "default"
category = breadcrumbCategory
message = breadcrumbMessage
Expand All @@ -134,7 +134,7 @@ public open class DefaultReplayBreadcrumbConverter : ReplayBreadcrumbConverter {
val httpStartTimestamp = breadcrumb.data[SpanDataConvention.HTTP_START_TIMESTAMP]
val httpEndTimestamp = breadcrumb.data[SpanDataConvention.HTTP_END_TIMESTAMP]
return RRWebSpanEvent().apply {
timestamp = breadcrumb.timestamp.time
timestamp = breadcrumb.timestampMs
op = "resource.http"
description = breadcrumb.data["url"] as String
// can be double if it was serialized to disk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ internal interface CaptureStrategy {

val urls = LinkedList<String>()
breadcrumbs.forEach { breadcrumb ->
if (breadcrumb.timestamp.time >= segmentTimestamp.time &&
breadcrumb.timestamp.time < endTimestamp.time
if (breadcrumb.timestampMs >= segmentTimestamp.time &&
breadcrumb.timestampMs < endTimestamp.time
) {
val rrwebEvent = options
.replayController
Expand Down
2 changes: 2 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public final class io/sentry/BaggageHeader {

public final class io/sentry/Breadcrumb : io/sentry/JsonSerializable, io/sentry/JsonUnknown {
public fun <init> ()V
public fun <init> (J)V
public fun <init> (Ljava/lang/String;)V
public fun <init> (Ljava/util/Date;)V
public static fun debug (Ljava/lang/String;)Lio/sentry/Breadcrumb;
Expand All @@ -111,6 +112,7 @@ public final class io/sentry/Breadcrumb : io/sentry/JsonSerializable, io/sentry/
public fun getMessage ()Ljava/lang/String;
public fun getOrigin ()Ljava/lang/String;
public fun getTimestamp ()Ljava/util/Date;
public fun getTimestampMs ()J
public fun getType ()Ljava/lang/String;
public fun getUnknown ()Ljava/util/Map;
public static fun graphqlDataFetcher (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/sentry/Breadcrumb;
Expand Down
25 changes: 19 additions & 6 deletions sentry/src/main/java/io/sentry/Breadcrumb.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public final class Breadcrumb implements JsonUnknown, JsonSerializable {

/** A timestamp representing when the breadcrumb occurred. */
private final @NotNull Date timestamp;
private final long timestamp;

/** If a message is provided, its rendered as text and the whitespace is preserved. */
private @Nullable String message;
Expand Down Expand Up @@ -51,7 +51,12 @@ public final class Breadcrumb implements JsonUnknown, JsonSerializable {
*
* @param timestamp the timestamp
*/
@SuppressWarnings("JavaUtilDate")
public Breadcrumb(final @NotNull Date timestamp) {
this.timestamp = timestamp.getTime();
}

public Breadcrumb(final long timestamp) {
this.timestamp = timestamp;
}

Expand Down Expand Up @@ -504,7 +509,7 @@ public static Breadcrumb fromMap(

/** Breadcrumb ctor */
public Breadcrumb() {
this(DateUtils.getCurrentDateTime());
this(System.currentTimeMillis());
}

/**
Expand All @@ -522,9 +527,17 @@ public Breadcrumb(@Nullable String message) {
*
* @return the timestamp
*/
@SuppressWarnings({"JdkObsolete", "JavaUtilDate"})
public long getTimestampMs() {
return timestamp;
}

/**
* Returns the Breadcrumb's timestamp as java.util.Date
*
* @return the timestamp
*/
public @NotNull Date getTimestamp() {
return (Date) timestamp.clone();
return DateUtils.getDateTime(timestamp);
}

/**
Expand Down Expand Up @@ -664,7 +677,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Breadcrumb that = (Breadcrumb) o;
return timestamp.getTime() == that.timestamp.getTime()
return timestamp == that.timestamp
&& Objects.equals(message, that.message)
&& Objects.equals(type, that.type)
&& Objects.equals(category, that.category)
Expand Down Expand Up @@ -704,7 +717,7 @@ public static final class JsonKeys {
public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger logger)
throws IOException {
writer.beginObject();
writer.name(JsonKeys.TIMESTAMP).value(logger, timestamp);
writer.name(JsonKeys.TIMESTAMP).value(logger, DateUtils.getDateTime(timestamp));
if (message != null) {
writer.name(JsonKeys.MESSAGE).value(message);
}
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ private static final class SortBreadcrumbsByDate implements Comparator<Breadcrum
@SuppressWarnings({"JdkObsolete", "JavaUtilDate"})
@Override
public int compare(final @NotNull Breadcrumb b1, final @NotNull Breadcrumb b2) {
return b1.getTimestamp().compareTo(b2.getTimestamp());
return Long.compare(b1.getTimestampMs(), b2.getTimestampMs());
}
}
}
3 changes: 2 additions & 1 deletion sentry/src/test/java/io/sentry/BreadcrumbTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertNotSame
import kotlin.test.assertNull
import kotlin.test.assertTrue

class BreadcrumbTest {

Expand Down Expand Up @@ -97,7 +98,7 @@ class BreadcrumbTest {
@Test
fun `breadcrumb has timestamp when created`() {
val breadcrumb = Breadcrumb()
assertNotNull(breadcrumb.timestamp)
assertTrue(breadcrumb.timestampMs > 0)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class BreadcrumbSerializationTest {
val actual = Breadcrumb.fromMap(map, SentryOptions())
val expected = fixture.getSut()

assertEquals(expected.timestamp, actual?.timestamp)
assertEquals(expected.timestampMs, actual?.timestampMs)
assertEquals(expected.message, actual?.message)
assertEquals(expected.type, actual?.type)
assertEquals(expected.data, actual?.data)
Expand Down

0 comments on commit b464cc6

Please sign in to comment.