Skip to content

Commit

Permalink
Merge 97634f7 into f122116
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanosiano authored Dec 5, 2022
2 parents f122116 + 97634f7 commit 4abc1c0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- Updated ProfileMeasurementValue types ([#2412](https://github.com/getsentry/sentry-java/pull/2412))
- No longer disable OpenTelemetry exporters in default Java Agent config ([#2408](https://github.com/getsentry/sentry-java/pull/2408))
- Fix `ClassNotFoundException` for `io.sentry.spring.SentrySpringServletContainerInitializer` in `sentry-spring-jakarta` ([#2411](https://github.com/getsentry/sentry-java/issues/2411))
- Fix `sentry-samples-spring-jakarta` ([#2411](https://github.com/getsentry/sentry-java/issues/2411))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ public void onFrameMetricCollected(
@NotNull FrameMetrics frameMetrics, float refreshRate) {
long frameTimestampRelativeNanos =
SystemClock.elapsedRealtimeNanos() - transactionStartNanos;

// We don't allow negative relative timestamps.
// So we add a check, even if this should never happen.
if (frameTimestampRelativeNanos < 0) {
return;
}
long durationNanos = frameMetrics.getMetric(FrameMetrics.TOTAL_DURATION);
// Most frames take just a few nanoseconds longer than the optimal calculated
// duration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
public final class ProfileMeasurementValue implements JsonUnknown, JsonSerializable {

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

public ProfileMeasurementValue() {
this(0L, 0);
}

public ProfileMeasurementValue(final @NotNull Long relativeStartNs, final @NotNull Number value) {
this.relativeStartNs = relativeStartNs;
this.value = value.toString();
this.relativeStartNs = relativeStartNs.toString();
this.value = value.doubleValue();
}

@Override
Expand All @@ -38,7 +38,7 @@ public boolean equals(Object o) {
ProfileMeasurementValue that = (ProfileMeasurementValue) o;
return Objects.equals(unknown, that.unknown)
&& relativeStartNs.equals(that.relativeStartNs)
&& value.equals(that.value);
&& value == that.value;
}

@Override
Expand Down Expand Up @@ -93,13 +93,13 @@ public static final class Deserializer implements JsonDeserializer<ProfileMeasur
final String nextName = reader.nextName();
switch (nextName) {
case JsonKeys.VALUE:
String value = reader.nextStringOrNull();
Double value = reader.nextDoubleOrNull();
if (value != null) {
data.value = value;
}
break;
case JsonKeys.START_NS:
Long startNs = reader.nextLongOrNull();
String startNs = reader.nextStringOrNull();
if (startNs != null) {
data.relativeStartNs = startNs;
}
Expand Down
10 changes: 5 additions & 5 deletions sentry/src/test/java/io/sentry/JsonSerializerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ class JsonSerializerTest {
ProfileMeasurement.ID_SCREEN_FRAME_RATES to
ProfileMeasurement(
ProfileMeasurement.UNIT_HZ,
listOf(ProfileMeasurementValue(1, 60.1F))
listOf(ProfileMeasurementValue(1, 60.1))
)
)
)
Expand Down Expand Up @@ -574,8 +574,8 @@ class JsonSerializerTest {
"unit" to ProfileMeasurement.UNIT_HZ,
"values" to listOf(
mapOf(
"value" to "60.1",
"elapsed_since_start_ns" to 1
"value" to 60.1,
"elapsed_since_start_ns" to "1"
)
)
)
Expand Down Expand Up @@ -710,7 +710,7 @@ class JsonSerializerTest {
val measurementValues = listOf(ProfileMeasurementValue(1, 2), ProfileMeasurementValue(3, 4))
val profileMeasurement = ProfileMeasurement(ProfileMeasurement.UNIT_NANOSECONDS, measurementValues)
val actual = serializeToString(profileMeasurement)
val expected = "{\"unit\":\"nanosecond\",\"values\":[{\"value\":\"2\",\"elapsed_since_start_ns\":1},{\"value\":\"4\",\"elapsed_since_start_ns\":3}]}"
val expected = "{\"unit\":\"nanosecond\",\"values\":[{\"value\":2.0,\"elapsed_since_start_ns\":\"1\"},{\"value\":4.0,\"elapsed_since_start_ns\":\"3\"}]}"
assertEquals(expected, actual)
}

Expand All @@ -734,7 +734,7 @@ class JsonSerializerTest {
fun `serializes profileMeasurementValue`() {
val profileMeasurementValue = ProfileMeasurementValue(1, 2)
val actual = serializeToString(profileMeasurementValue)
val expected = "{\"value\":\"2\",\"elapsed_since_start_ns\":1}"
val expected = "{\"value\":2.0,\"elapsed_since_start_ns\":\"1\"}"
assertEquals(expected, actual)
}

Expand Down

0 comments on commit 4abc1c0

Please sign in to comment.