From 3aff6fa7e2f9b0d39b82d06beb7c92aeded912ca Mon Sep 17 00:00:00 2001 From: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:11:30 +0200 Subject: [PATCH] misc(ttd): Add Android Logger when new frame event is not emitted (#4081) --- CHANGELOG.md | 1 + .../react/RNSentryOnDrawReporterManager.java | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65fb381f6..26425d932 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ ### Changes +- Add Android Logger when new frame event is not emitted ([#4081](https://github.com/getsentry/sentry-react-native/pull/4081)) - React Native Tracing Deprecations ([#4073](https://github.com/getsentry/sentry-react-native/pull/4073)) - `new ReactNativeTracing` to `reactNativeTracingIntegration()` - `new ReactNavigationInstrumentation` to `reactNativeTracingIntegration()`. diff --git a/android/src/main/java/io/sentry/react/RNSentryOnDrawReporterManager.java b/android/src/main/java/io/sentry/react/RNSentryOnDrawReporterManager.java index 0026082ad..a33f4fc1c 100644 --- a/android/src/main/java/io/sentry/react/RNSentryOnDrawReporterManager.java +++ b/android/src/main/java/io/sentry/react/RNSentryOnDrawReporterManager.java @@ -18,8 +18,10 @@ import java.util.Map; +import io.sentry.ILogger; import io.sentry.SentryDate; import io.sentry.SentryDateProvider; +import io.sentry.SentryLevel; import io.sentry.android.core.AndroidLogger; import io.sentry.android.core.BuildInfoProvider; import io.sentry.android.core.SentryAndroidDateProvider; @@ -68,6 +70,8 @@ public Map getExportedCustomBubblingEventTypeConstants() { public static class RNSentryOnDrawReporterView extends View { + private static final ILogger logger = new AndroidLogger("RNSentryOnDrawReporterView"); + private final @Nullable ReactApplicationContext reactContext; private final @NotNull SentryDateProvider dateProvider = new SentryAndroidDateProvider(); private final @Nullable Runnable emitInitialDisplayEvent; @@ -96,6 +100,7 @@ public void setFullDisplay(boolean fullDisplay) { return; } + logger.log(SentryLevel.DEBUG, "[TimeToDisplay] Register full display event emitter."); registerForNextDraw(emitFullDisplayEvent); } @@ -104,16 +109,27 @@ public void setInitialDisplay(boolean initialDisplay) { return; } + logger.log(SentryLevel.DEBUG, "[TimeToDisplay] Register initial display event emitter."); registerForNextDraw(emitInitialDisplayEvent); } private void registerForNextDraw(@Nullable Runnable emitter) { + if (emitter == null) { + logger.log(SentryLevel.ERROR, "[TimeToDisplay] Won't emit next frame drawn event, emitter is null."); + return; + } + if (buildInfo == null) { + logger.log(SentryLevel.ERROR, "[TimeToDisplay] Won't emit next frame drawn event, buildInfo is null."); + return; + } if (reactContext == null) { + logger.log(SentryLevel.ERROR, "[TimeToDisplay] Won't emit next frame drawn event, reactContext is null."); return; } @Nullable Activity activity = reactContext.getCurrentActivity(); - if (activity == null || emitter == null || buildInfo == null) { + if (activity == null) { + logger.log(SentryLevel.ERROR, "[TimeToDisplay] Won't emit next frame drawn event, reactContext is null."); return; } @@ -129,6 +145,7 @@ private void emitDisplayEvent(String type) { event.putDouble("newFrameTimestampInSeconds", endDate.nanoTimestamp() / 1e9); if (reactContext == null) { + logger.log(SentryLevel.ERROR, "[TimeToDisplay] Recorded next frame draw but can't emit the event, reactContext is null."); return; } reactContext