Skip to content

Commit 20d7d3d

Browse files
authored
Updated ProfileMeasurementValue types (#2412)
* changed ProfileMeasurementValue types: timestamp is now a string and the value is a double added a check against negative timestamps
1 parent 1e1ab7f commit 20d7d3d

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Fixes
66

7+
- Updated ProfileMeasurementValue types ([#2412](https://github.com/getsentry/sentry-java/pull/2412))
78
- Clear window reference only on activity stop in profileMeasurements collector ([#2407](https://github.com/getsentry/sentry-java/pull/2407))
89
- No longer disable OpenTelemetry exporters in default Java Agent config ([#2408](https://github.com/getsentry/sentry-java/pull/2408))
910
- Fix `ClassNotFoundException` for `io.sentry.spring.SentrySpringServletContainerInitializer` in `sentry-spring-jakarta` ([#2411](https://github.com/getsentry/sentry-java/issues/2411))

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ public void onFrameMetricCollected(
198198
@NotNull FrameMetrics frameMetrics, float refreshRate) {
199199
long frameTimestampRelativeNanos =
200200
SystemClock.elapsedRealtimeNanos() - transactionStartNanos;
201+
202+
// We don't allow negative relative timestamps.
203+
// So we add a check, even if this should never happen.
204+
if (frameTimestampRelativeNanos < 0) {
205+
return;
206+
}
201207
long durationNanos = frameMetrics.getMetric(FrameMetrics.TOTAL_DURATION);
202208
// Most frames take just a few nanoseconds longer than the optimal calculated
203209
// duration.

sentry/src/main/java/io/sentry/profilemeasurements/ProfileMeasurementValue.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
public final class ProfileMeasurementValue implements JsonUnknown, JsonSerializable {
2020

2121
private @Nullable Map<String, Object> unknown;
22-
private @NotNull Long relativeStartNs; // timestamp in nanoseconds this frame was started
23-
private @NotNull String value; // frame duration in nanoseconds
22+
private @NotNull String relativeStartNs; // timestamp in nanoseconds this frame was started
23+
private double value; // frame duration in nanoseconds
2424

2525
public ProfileMeasurementValue() {
2626
this(0L, 0);
2727
}
2828

2929
public ProfileMeasurementValue(final @NotNull Long relativeStartNs, final @NotNull Number value) {
30-
this.relativeStartNs = relativeStartNs;
31-
this.value = value.toString();
30+
this.relativeStartNs = relativeStartNs.toString();
31+
this.value = value.doubleValue();
3232
}
3333

3434
@Override
@@ -38,7 +38,7 @@ public boolean equals(Object o) {
3838
ProfileMeasurementValue that = (ProfileMeasurementValue) o;
3939
return Objects.equals(unknown, that.unknown)
4040
&& relativeStartNs.equals(that.relativeStartNs)
41-
&& value.equals(that.value);
41+
&& value == that.value;
4242
}
4343

4444
@Override
@@ -93,13 +93,13 @@ public static final class Deserializer implements JsonDeserializer<ProfileMeasur
9393
final String nextName = reader.nextName();
9494
switch (nextName) {
9595
case JsonKeys.VALUE:
96-
String value = reader.nextStringOrNull();
96+
Double value = reader.nextDoubleOrNull();
9797
if (value != null) {
9898
data.value = value;
9999
}
100100
break;
101101
case JsonKeys.START_NS:
102-
Long startNs = reader.nextLongOrNull();
102+
String startNs = reader.nextStringOrNull();
103103
if (startNs != null) {
104104
data.relativeStartNs = startNs;
105105
}

sentry/src/test/java/io/sentry/JsonSerializerTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ class JsonSerializerTest {
520520
ProfileMeasurement.ID_SCREEN_FRAME_RATES to
521521
ProfileMeasurement(
522522
ProfileMeasurement.UNIT_HZ,
523-
listOf(ProfileMeasurementValue(1, 60.1F))
523+
listOf(ProfileMeasurementValue(1, 60.1))
524524
)
525525
)
526526
)
@@ -574,8 +574,8 @@ class JsonSerializerTest {
574574
"unit" to ProfileMeasurement.UNIT_HZ,
575575
"values" to listOf(
576576
mapOf(
577-
"value" to "60.1",
578-
"elapsed_since_start_ns" to 1
577+
"value" to 60.1,
578+
"elapsed_since_start_ns" to "1"
579579
)
580580
)
581581
)
@@ -710,7 +710,7 @@ class JsonSerializerTest {
710710
val measurementValues = listOf(ProfileMeasurementValue(1, 2), ProfileMeasurementValue(3, 4))
711711
val profileMeasurement = ProfileMeasurement(ProfileMeasurement.UNIT_NANOSECONDS, measurementValues)
712712
val actual = serializeToString(profileMeasurement)
713-
val expected = "{\"unit\":\"nanosecond\",\"values\":[{\"value\":\"2\",\"elapsed_since_start_ns\":1},{\"value\":\"4\",\"elapsed_since_start_ns\":3}]}"
713+
val expected = "{\"unit\":\"nanosecond\",\"values\":[{\"value\":2.0,\"elapsed_since_start_ns\":\"1\"},{\"value\":4.0,\"elapsed_since_start_ns\":\"3\"}]}"
714714
assertEquals(expected, actual)
715715
}
716716

@@ -734,7 +734,7 @@ class JsonSerializerTest {
734734
fun `serializes profileMeasurementValue`() {
735735
val profileMeasurementValue = ProfileMeasurementValue(1, 2)
736736
val actual = serializeToString(profileMeasurementValue)
737-
val expected = "{\"value\":\"2\",\"elapsed_since_start_ns\":1}"
737+
val expected = "{\"value\":2.0,\"elapsed_since_start_ns\":\"1\"}"
738738
assertEquals(expected, actual)
739739
}
740740

0 commit comments

Comments
 (0)