|
61 | 61 | import io.sentry.SentryExecutorService; |
62 | 62 | import io.sentry.SentryLevel; |
63 | 63 | import io.sentry.SentryOptions; |
| 64 | +import io.sentry.SentryReplayOptions; |
64 | 65 | import io.sentry.UncaughtExceptionHandlerIntegration; |
65 | 66 | import io.sentry.android.core.AndroidLogger; |
66 | 67 | import io.sentry.android.core.AndroidProfiler; |
|
79 | 80 | import io.sentry.android.core.performance.AppStartMetrics; |
80 | 81 | import io.sentry.protocol.SdkVersion; |
81 | 82 | import io.sentry.protocol.SentryException; |
| 83 | +import io.sentry.protocol.SentryId; |
82 | 84 | import io.sentry.protocol.SentryPackage; |
83 | 85 | import io.sentry.protocol.User; |
84 | 86 | import io.sentry.protocol.ViewHierarchy; |
@@ -252,7 +254,9 @@ public void initNativeSdk(final ReadableMap rnOptions, Promise promise) { |
252 | 254 | if (rnOptions.hasKey("enableNdk")) { |
253 | 255 | options.setEnableNdk(rnOptions.getBoolean("enableNdk")); |
254 | 256 | } |
255 | | - |
| 257 | + if (rnOptions.hasKey("_experiments")) { |
| 258 | + options.getExperimental().setSessionReplay(getReplayOptions(rnOptions)); |
| 259 | + } |
256 | 260 | options.setBeforeSend((event, hint) -> { |
257 | 261 | // React native internally throws a JavascriptException |
258 | 262 | // Since we catch it before that, we don't want to send this one |
@@ -293,6 +297,37 @@ public void initNativeSdk(final ReadableMap rnOptions, Promise promise) { |
293 | 297 | promise.resolve(true); |
294 | 298 | } |
295 | 299 |
|
| 300 | + private SentryReplayOptions getReplayOptions(@NotNull ReadableMap rnOptions) { |
| 301 | + @NotNull final SentryReplayOptions androidReplayOptions = new SentryReplayOptions(); |
| 302 | + |
| 303 | + @Nullable final ReadableMap rnExperimentsOptions = rnOptions.getMap("_experiments"); |
| 304 | + if (rnExperimentsOptions == null) { |
| 305 | + return androidReplayOptions; |
| 306 | + } |
| 307 | + |
| 308 | + if (!(rnExperimentsOptions.hasKey("replaysSessionSampleRate") || rnExperimentsOptions.hasKey("replaysOnErrorSampleRate"))) { |
| 309 | + return androidReplayOptions; |
| 310 | + } |
| 311 | + |
| 312 | + androidReplayOptions.setSessionSampleRate(rnExperimentsOptions.hasKey("replaysSessionSampleRate") |
| 313 | + ? rnExperimentsOptions.getDouble("replaysSessionSampleRate") : null); |
| 314 | + androidReplayOptions.setErrorSampleRate(rnExperimentsOptions.hasKey("replaysOnErrorSampleRate") |
| 315 | + ? rnExperimentsOptions.getDouble("replaysOnErrorSampleRate") : null); |
| 316 | + |
| 317 | + if (!rnOptions.hasKey("mobileReplayOptions")) { |
| 318 | + return androidReplayOptions; |
| 319 | + } |
| 320 | + @Nullable final ReadableMap rnMobileReplayOptions = rnOptions.getMap("mobileReplayOptions"); |
| 321 | + if (rnMobileReplayOptions == null) { |
| 322 | + return androidReplayOptions; |
| 323 | + } |
| 324 | + |
| 325 | + androidReplayOptions.setRedactAllText(!rnMobileReplayOptions.hasKey("maskAllText") || rnMobileReplayOptions.getBoolean("maskAllText")); |
| 326 | + androidReplayOptions.setRedactAllImages(!rnMobileReplayOptions.hasKey("maskAllImages") || rnMobileReplayOptions.getBoolean("maskAllImages")); |
| 327 | + |
| 328 | + return androidReplayOptions; |
| 329 | + } |
| 330 | + |
296 | 331 | public void crash() { |
297 | 332 | throw new RuntimeException("TEST - Sentry Client Crash (only works in release mode)"); |
298 | 333 | } |
@@ -394,6 +429,24 @@ public void fetchNativeFrames(Promise promise) { |
394 | 429 | } |
395 | 430 | } |
396 | 431 |
|
| 432 | + public void captureReplay(boolean isHardCrash, Promise promise) { |
| 433 | + Sentry.getCurrentHub().getOptions().getReplayController().sendReplay(isHardCrash, null, null); |
| 434 | + promise.resolve(getCurrentReplayId()); |
| 435 | + } |
| 436 | + |
| 437 | + public @Nullable String getCurrentReplayId() { |
| 438 | + final @Nullable IScope scope = InternalSentrySdk.getCurrentScope(); |
| 439 | + if (scope == null) { |
| 440 | + return null; |
| 441 | + } |
| 442 | + |
| 443 | + final @NotNull SentryId id = scope.getReplayId(); |
| 444 | + if (id == SentryId.EMPTY_ID) { |
| 445 | + return null; |
| 446 | + } |
| 447 | + return id.toString(); |
| 448 | + } |
| 449 | + |
397 | 450 | public void captureEnvelope(String rawBytes, ReadableMap options, Promise promise) { |
398 | 451 | byte[] bytes = Base64.decode(rawBytes, Base64.DEFAULT); |
399 | 452 |
|
|
0 commit comments