Skip to content
Draft
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
> make sure you follow our [migration guide](https://docs.sentry.io/platforms/react-native/migration/) first.
<!-- prettier-ignore-end -->

## Unreleased

### Fixes

- Use sentry-java `getFramesDelay` API instead of custom frame delay collector ([#6074](https://github.com/getsentry/sentry-react-native/pull/6074))

## 8.10.0

### Features
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import io.sentry.android.core.SentryShakeDetector;
import io.sentry.android.core.ViewHierarchyEventProcessor;
import io.sentry.android.core.internal.debugmeta.AssetsDebugMetaLoader;
import io.sentry.android.core.SentryFramesDelayResult;
import io.sentry.android.core.internal.util.SentryFrameMetricsCollector;
import io.sentry.android.core.performance.AppStartMetrics;
import io.sentry.protocol.Geo;
Expand Down Expand Up @@ -98,7 +99,8 @@ public class RNSentryModuleImpl {
private final ReactApplicationContext reactApplicationContext;
private final PackageInfo packageInfo;
private FrameMetricsAggregator frameMetricsAggregator = null;
private final RNSentryFrameDelayCollector frameDelayCollector = new RNSentryFrameDelayCollector();
private @Nullable SentryFrameMetricsCollector frameMetricsCollector = null;
private @Nullable String frameMetricsListenerId = null;
private boolean androidXAvailable;

@VisibleForTesting static long lastStartTimestampMs = -1;
Expand Down Expand Up @@ -413,9 +415,15 @@ public void fetchNativeFramesDelay(
long startNanos = nowNanos - (long) (startOffsetSeconds * 1e9);
long endNanos = nowNanos - (long) (endOffsetSeconds * 1e9);

double delaySeconds = frameDelayCollector.getFramesDelay(startNanos, endNanos);
if (delaySeconds >= 0) {
promise.resolve(delaySeconds);
if (frameMetricsCollector == null) {
promise.resolve(null);
return;
}

SentryFramesDelayResult result =
frameMetricsCollector.getFramesDelay(startNanos, endNanos);
if (result.getDelaySeconds() >= 0) {
promise.resolve(result.getDelaySeconds());
} else {
promise.resolve(null);
}
Expand Down Expand Up @@ -747,12 +755,22 @@ public void enableNativeFramesTracking() {
if (options instanceof SentryAndroidOptions) {
final SentryFrameMetricsCollector collector =
((SentryAndroidOptions) options).getFrameMetricsCollector();
if (frameDelayCollector.start(collector)) {
logger.log(SentryLevel.INFO, "RNSentryFrameDelayCollector installed.");
if (collector != null) {
// Register a no-op listener to ensure frame metrics collection is active.
// This is needed so that getFramesDelay() has data to query.
stopFrameMetricsCollection();
frameMetricsCollector = collector;
frameMetricsListenerId =
collector.startCollection(
(startNanos, endNanos, durationNanos, delayNanos, isSlow, isFrozen, refreshRate)
-> {});
if (frameMetricsListenerId != null) {
logger.log(SentryLevel.INFO, "SentryFrameMetricsCollector listener installed.");
}
}
}
} catch (Throwable ignored) { // NOPMD - We don't want to crash in any case
logger.log(SentryLevel.WARNING, "Error starting RNSentryFrameDelayCollector.");
logger.log(SentryLevel.WARNING, "Error starting frame metrics collection.");
}
}

Expand All @@ -761,7 +779,15 @@ public void disableNativeFramesTracking() {
frameMetricsAggregator.stop();
frameMetricsAggregator = null;
}
frameDelayCollector.stop();
stopFrameMetricsCollection();
}

private void stopFrameMetricsCollection() {
if (frameMetricsCollector != null && frameMetricsListenerId != null) {
frameMetricsCollector.stopCollection(frameMetricsListenerId);
}
frameMetricsCollector = null;
frameMetricsListenerId = null;
}

public void getNewScreenTimeToDisplay(Promise promise) {
Expand Down
Loading