Skip to content

Commit 9295f0f

Browse files
authored
[SR] Add sendReplay method for Hybrid SDKs
2 parents bdd9db5 + e836f49 commit 9295f0f

File tree

8 files changed

+36
-20
lines changed

8 files changed

+36
-20
lines changed

sentry-android-replay/api/sentry-android-replay.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public final class io/sentry/android/replay/ReplayIntegration : android/content/
5252
public fun pause ()V
5353
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
5454
public fun resume ()V
55+
public fun sendReplay (Ljava/lang/Boolean;Ljava/lang/String;Lio/sentry/Hint;)V
5556
public fun sendReplayForEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;)V
5657
public fun start ()V
5758
public fun stop ()V

sentry-android-replay/src/main/java/io/sentry/android/replay/ReplayIntegration.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,20 @@ public class ReplayIntegration(
138138
return
139139
}
140140

141+
sendReplay(event.isCrashed, event.eventId.toString(), hint)
142+
}
143+
144+
override fun sendReplay(isCrashed: Boolean?, eventId: String?, hint: Hint?) {
145+
if (!isEnabled.get() || !isRecording.get()) {
146+
return
147+
}
148+
141149
if (SentryId.EMPTY_ID.equals(captureStrategy?.currentReplayId?.get())) {
142-
options.logger.log(DEBUG, "Replay id is not set, not capturing for event %s", event.eventId)
150+
options.logger.log(DEBUG, "Replay id is not set, not capturing for event %s", eventId)
143151
return
144152
}
145153

146-
captureStrategy?.sendReplayForEvent(event, hint, onSegmentSent = { captureStrategy?.currentSegment?.getAndIncrement() })
154+
captureStrategy?.sendReplayForEvent(isCrashed == true, eventId, hint, onSegmentSent = { captureStrategy?.currentSegment?.getAndIncrement() })
147155
captureStrategy = captureStrategy?.convert()
148156
}
149157

sentry-android-replay/src/main/java/io/sentry/android/replay/capture/BufferCaptureStrategy.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package io.sentry.android.replay.capture
33
import io.sentry.DateUtils
44
import io.sentry.Hint
55
import io.sentry.IHub
6-
import io.sentry.SentryEvent
76
import io.sentry.SentryLevel.ERROR
87
import io.sentry.SentryLevel.INFO
98
import io.sentry.SentryOptions
@@ -41,14 +40,16 @@ internal class BufferCaptureStrategy(
4140
super.stop()
4241
}
4342

44-
override fun sendReplayForEvent(event: SentryEvent, hint: Hint, onSegmentSent: () -> Unit) {
43+
override fun sendReplayForEvent(
44+
isCrashed: Boolean,
45+
eventId: String?,
46+
hint: Hint?,
47+
onSegmentSent: () -> Unit
48+
) {
4549
val sampled = random.sample(options.experimental.sessionReplay.errorSampleRate)
4650

47-
if (sampled) {
48-
// don't ask me why
49-
event.setTag("replayId", currentReplayId.get().toString())
50-
} else {
51-
options.logger.log(INFO, "Replay wasn't sampled by errorSampleRate, not capturing for event %s", event.eventId)
51+
if (!sampled) {
52+
options.logger.log(INFO, "Replay wasn't sampled by errorSampleRate, not capturing for event %s", eventId)
5253
return
5354
}
5455

@@ -83,7 +84,7 @@ internal class BufferCaptureStrategy(
8384
BUFFER
8485
)
8586
if (segment is ReplaySegment.Created) {
86-
segment.capture(hub, hint)
87+
segment.capture(hub, hint ?: Hint())
8788

8889
// we only want to increment segment_id in the case of success, but currentSegment
8990
// might be irrelevant since we changed strategies, so in the callback we increment

sentry-android-replay/src/main/java/io/sentry/android/replay/capture/CaptureStrategy.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.sentry.android.replay.capture
22

33
import io.sentry.Hint
4-
import io.sentry.SentryEvent
54
import io.sentry.android.replay.ReplayCache
65
import io.sentry.android.replay.ScreenshotRecorderConfig
76
import io.sentry.protocol.SentryId
@@ -22,7 +21,7 @@ internal interface CaptureStrategy {
2221

2322
fun resume()
2423

25-
fun sendReplayForEvent(event: SentryEvent, hint: Hint, onSegmentSent: () -> Unit)
24+
fun sendReplayForEvent(isCrashed: Boolean, eventId: String?, hint: Hint?, onSegmentSent: () -> Unit)
2625

2726
fun onScreenshotRecorded(store: ReplayCache.(frameTimestamp: Long) -> Unit)
2827

sentry-android-replay/src/main/java/io/sentry/android/replay/capture/SessionCaptureStrategy.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package io.sentry.android.replay.capture
33
import io.sentry.DateUtils
44
import io.sentry.Hint
55
import io.sentry.IHub
6-
import io.sentry.SentryEvent
76
import io.sentry.SentryLevel.DEBUG
87
import io.sentry.SentryLevel.INFO
98
import io.sentry.SentryOptions
@@ -58,16 +57,14 @@ internal class SessionCaptureStrategy(
5857
super.stop()
5958
}
6059

61-
override fun sendReplayForEvent(event: SentryEvent, hint: Hint, onSegmentSent: () -> Unit) {
62-
// don't ask me why
63-
event.setTag("replayId", currentReplayId.get().toString())
64-
if (!event.isCrashed) {
65-
options.logger.log(DEBUG, "Replay is already running in 'session' mode, not capturing for event %s", event.eventId)
60+
override fun sendReplayForEvent(isCrashed: Boolean, eventId: String?, hint: Hint?, onSegmentSent: () -> Unit) {
61+
if (!isCrashed) {
62+
options.logger.log(DEBUG, "Replay is already running in 'session' mode, not capturing for event %s", eventId)
6663
} else {
67-
options.logger.log(DEBUG, "Replay is already running in 'session' mode, capturing last segment for crashed event %s", event.eventId)
64+
options.logger.log(DEBUG, "Replay is already running in 'session' mode, capturing last segment for crashed event %s", eventId)
6865
createCurrentSegment("send_replay_for_event") { segment ->
6966
if (segment is ReplaySegment.Created) {
70-
segment.capture(hub, hint)
67+
segment.capture(hub, hint ?: Hint())
7168
}
7269
}
7370
}

sentry/api/sentry.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ public final class io/sentry/NoOpReplayController : io/sentry/ReplayController {
12591259
public fun isRecording ()Z
12601260
public fun pause ()V
12611261
public fun resume ()V
1262+
public fun sendReplay (Ljava/lang/Boolean;Ljava/lang/String;Lio/sentry/Hint;)V
12621263
public fun sendReplayForEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;)V
12631264
public fun start ()V
12641265
public fun stop ()V
@@ -1662,6 +1663,7 @@ public abstract interface class io/sentry/ReplayController {
16621663
public abstract fun isRecording ()Z
16631664
public abstract fun pause ()V
16641665
public abstract fun resume ()V
1666+
public abstract fun sendReplay (Ljava/lang/Boolean;Ljava/lang/String;Lio/sentry/Hint;)V
16651667
public abstract fun sendReplayForEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;)V
16661668
public abstract fun start ()V
16671669
public abstract fun stop ()V

sentry/src/main/java/io/sentry/NoOpReplayController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.sentry.protocol.SentryId;
44
import org.jetbrains.annotations.NotNull;
5+
import org.jetbrains.annotations.Nullable;
56

67
public final class NoOpReplayController implements ReplayController {
78

@@ -33,6 +34,10 @@ public boolean isRecording() {
3334
@Override
3435
public void sendReplayForEvent(@NotNull SentryEvent event, @NotNull Hint hint) {}
3536

37+
@Override
38+
public void sendReplay(
39+
@Nullable Boolean isCrashed, @Nullable String eventId, @Nullable Hint hint) {}
40+
3641
@Override
3742
public @NotNull SentryId getReplayId() {
3843
return SentryId.EMPTY_ID;

sentry/src/main/java/io/sentry/ReplayController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.sentry.protocol.SentryId;
44
import org.jetbrains.annotations.ApiStatus;
55
import org.jetbrains.annotations.NotNull;
6+
import org.jetbrains.annotations.Nullable;
67

78
@ApiStatus.Internal
89
public interface ReplayController {
@@ -18,6 +19,8 @@ public interface ReplayController {
1819

1920
void sendReplayForEvent(@NotNull SentryEvent event, @NotNull Hint hint);
2021

22+
void sendReplay(@Nullable Boolean isCrashed, @Nullable String eventId, @Nullable Hint hint);
23+
2124
@NotNull
2225
SentryId getReplayId();
2326
}

0 commit comments

Comments
 (0)