Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Internal

- Reduce timestamp parsing and formatting overhead with Sentry-specific ISO-8601 handling. ([#5602](https://github.com/getsentry/sentry-java/pull/5602))

## 8.45.0

### Features
Expand Down
16 changes: 16 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ limitations under the License.

---

## Howard Hinnant — Date Algorithms (Public Domain)

**Source:** https://howardhinnant.github.io/date_algorithms.html<br>
**License:** Public Domain<br>
**Copyright:** None; public domain dedication by Howard Hinnant

### Scope

The Sentry Java SDK includes adapted civil date conversion algorithms from Howard Hinnant's date algorithms for UTC ISO 8601 timestamp parsing and formatting. The code resides in `io.sentry.vendor.SentryIso8601Utils`.

```
Consider these donated to the public domain.
```

---

## Android Open Source Project — Base64 (Apache 2.0)

**Source:** https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/core/java/android/util/Base64.java<br>
Expand Down
5 changes: 5 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -8076,6 +8076,11 @@ public class io/sentry/vendor/Base64 {
public static fun encodeToString ([BIII)Ljava/lang/String;
}

public final class io/sentry/vendor/SentryIso8601Utils {
public static fun formatTimestamp (J)Ljava/lang/String;
public static fun parseTimestamp (Ljava/lang/String;)J
}

public class io/sentry/vendor/gson/internal/bind/util/ISO8601Utils {
public static final field TIMEZONE_UTC Ljava/util/TimeZone;
public fun <init> ()V
Expand Down
7 changes: 6 additions & 1 deletion sentry/src/main/java/io/sentry/Breadcrumb.java
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,12 @@ 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, getTimestamp());
writer
.name(JsonKeys.TIMESTAMP)
.value(
timestampMs != null
? DateUtils.getTimestampFromMillis(timestampMs)
: DateUtils.getTimestamp(getTimestamp()));
if (message != null) {
writer.name(JsonKeys.MESSAGE).value(message);
}
Expand Down
22 changes: 15 additions & 7 deletions sentry/src/main/java/io/sentry/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import static io.sentry.vendor.gson.internal.bind.util.ISO8601Utils.TIMEZONE_UTC;

import io.sentry.vendor.gson.internal.bind.util.ISO8601Utils;
import io.sentry.vendor.SentryIso8601Utils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.ParsePosition;
import java.util.Calendar;
import java.util.Date;
import org.jetbrains.annotations.ApiStatus;
Expand All @@ -15,6 +13,7 @@

/** Utilities to deal with dates */
@ApiStatus.Internal
@SuppressWarnings("JavaUtilDate")
public final class DateUtils {

private DateUtils() {}
Expand All @@ -39,8 +38,8 @@ private DateUtils() {}
public static @NotNull Date getDateTime(final @NotNull String timestamp)
throws IllegalArgumentException {
try {
return ISO8601Utils.parse(timestamp, new ParsePosition(0));
} catch (ParseException e) {
return getDateTime(SentryIso8601Utils.parseTimestamp(timestamp));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("timestamp is not ISO format " + timestamp);
}
}
Expand All @@ -51,7 +50,6 @@ private DateUtils() {}
* @param timestamp millis eg 1581410911.988 (1581410911 seconds and 988 millis)
* @return the UTC Date
*/
@SuppressWarnings("JdkObsolete")
public static @NotNull Date getDateTimeWithMillisPrecision(final @NotNull String timestamp)
throws IllegalArgumentException {
try {
Expand All @@ -69,7 +67,17 @@ private DateUtils() {}
* @return the UTC/ISO 8601 timestamp
*/
public static @NotNull String getTimestamp(final @NotNull Date date) {
return ISO8601Utils.format(date, true);
return getTimestampFromMillis(date.getTime());
}

/**
* Get the UTC/ISO 8601 timestamp from millis.
*
* @param millis the UTC millis from the epoch
* @return the UTC/ISO 8601 timestamp
*/
static @NotNull String getTimestampFromMillis(final long millis) {
return SentryIso8601Utils.formatTimestamp(millis);
}

/**
Expand Down
Loading
Loading