Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated ProfileMeasurementValue types #2412

Merged
merged 4 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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))
- Clear window reference only on activity stop in profileMeasurements collector ([#2407](https://github.com/getsentry/sentry-java/pull/2407))
- 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))
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