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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR] Add sendReplay method for Hybrid SDKs #3383

Merged
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 sentry-android-replay/api/sentry-android-replay.api
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public final class io/sentry/android/replay/ReplayIntegration : android/content/
public fun pause ()V
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
public fun resume ()V
public fun sendReplay (Ljava/lang/Boolean;Ljava/lang/String;Lio/sentry/Hint;)V
public fun sendReplayForEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;)V
public fun start ()V
public fun stop ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,20 @@ public class ReplayIntegration(
return
}

sendReplay(event.isCrashed, event.eventId.toString(), hint)
}

override fun sendReplay(isCrashed: Boolean?, eventId: String?, hint: Hint?) {
if (!isEnabled.get() || !isRecording.get()) {
return
}

if (SentryId.EMPTY_ID.equals(captureStrategy?.currentReplayId?.get())) {
options.logger.log(DEBUG, "Replay id is not set, not capturing for event %s", event.eventId)
options.logger.log(DEBUG, "Replay id is not set, not capturing for event %s", eventId)
return
}

captureStrategy?.sendReplayForEvent(event, hint, onSegmentSent = { captureStrategy?.currentSegment?.getAndIncrement() })
captureStrategy?.sendReplayForEvent(isCrashed == true, eventId, hint, onSegmentSent = { captureStrategy?.currentSegment?.getAndIncrement() })
captureStrategy = captureStrategy?.convert()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.sentry.android.replay.capture
import io.sentry.DateUtils
import io.sentry.Hint
import io.sentry.IHub
import io.sentry.SentryEvent
import io.sentry.SentryLevel.ERROR
import io.sentry.SentryLevel.INFO
import io.sentry.SentryOptions
Expand Down Expand Up @@ -41,14 +40,16 @@ internal class BufferCaptureStrategy(
super.stop()
}

override fun sendReplayForEvent(event: SentryEvent, hint: Hint, onSegmentSent: () -> Unit) {
override fun sendReplayForEvent(
isCrashed: Boolean,
eventId: String?,
hint: Hint?,
onSegmentSent: () -> Unit
) {
val sampled = random.sample(options.experimental.sessionReplay.errorSampleRate)

if (sampled) {
// don't ask me why
event.setTag("replayId", currentReplayId.get().toString())
} else {
options.logger.log(INFO, "Replay wasn't sampled by errorSampleRate, not capturing for event %s", event.eventId)
if (!sampled) {
options.logger.log(INFO, "Replay wasn't sampled by errorSampleRate, not capturing for event %s", eventId)
return
}

Expand Down Expand Up @@ -83,7 +84,7 @@ internal class BufferCaptureStrategy(
BUFFER
)
if (segment is ReplaySegment.Created) {
segment.capture(hub, hint)
segment.capture(hub, hint ?: Hint())

// we only want to increment segment_id in the case of success, but currentSegment
// might be irrelevant since we changed strategies, so in the callback we increment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.sentry.android.replay.capture

import io.sentry.Hint
import io.sentry.SentryEvent
import io.sentry.android.replay.ReplayCache
import io.sentry.android.replay.ScreenshotRecorderConfig
import io.sentry.protocol.SentryId
Expand All @@ -22,7 +21,7 @@ internal interface CaptureStrategy {

fun resume()

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.sentry.android.replay.capture
import io.sentry.DateUtils
import io.sentry.Hint
import io.sentry.IHub
import io.sentry.SentryEvent
import io.sentry.SentryLevel.DEBUG
import io.sentry.SentryLevel.INFO
import io.sentry.SentryOptions
Expand Down Expand Up @@ -58,16 +57,14 @@ internal class SessionCaptureStrategy(
super.stop()
}

override fun sendReplayForEvent(event: SentryEvent, hint: Hint, onSegmentSent: () -> Unit) {
// don't ask me why
event.setTag("replayId", currentReplayId.get().toString())
if (!event.isCrashed) {
options.logger.log(DEBUG, "Replay is already running in 'session' mode, not capturing for event %s", event.eventId)
override fun sendReplayForEvent(isCrashed: Boolean, eventId: String?, hint: Hint?, onSegmentSent: () -> Unit) {
if (!isCrashed) {
options.logger.log(DEBUG, "Replay is already running in 'session' mode, not capturing for event %s", eventId)
} else {
options.logger.log(DEBUG, "Replay is already running in 'session' mode, capturing last segment for crashed event %s", event.eventId)
options.logger.log(DEBUG, "Replay is already running in 'session' mode, capturing last segment for crashed event %s", eventId)
createCurrentSegment("send_replay_for_event") { segment ->
if (segment is ReplaySegment.Created) {
segment.capture(hub, hint)
segment.capture(hub, hint ?: Hint())
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ public final class io/sentry/NoOpReplayController : io/sentry/ReplayController {
public fun isRecording ()Z
public fun pause ()V
public fun resume ()V
public fun sendReplay (Ljava/lang/Boolean;Ljava/lang/String;Lio/sentry/Hint;)V
public fun sendReplayForEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;)V
public fun start ()V
public fun stop ()V
Expand Down Expand Up @@ -1662,6 +1663,7 @@ public abstract interface class io/sentry/ReplayController {
public abstract fun isRecording ()Z
public abstract fun pause ()V
public abstract fun resume ()V
public abstract fun sendReplay (Ljava/lang/Boolean;Ljava/lang/String;Lio/sentry/Hint;)V
public abstract fun sendReplayForEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;)V
public abstract fun start ()V
public abstract fun stop ()V
Expand Down
5 changes: 5 additions & 0 deletions sentry/src/main/java/io/sentry/NoOpReplayController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.sentry.protocol.SentryId;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class NoOpReplayController implements ReplayController {

Expand Down Expand Up @@ -33,6 +34,10 @@ public boolean isRecording() {
@Override
public void sendReplayForEvent(@NotNull SentryEvent event, @NotNull Hint hint) {}

@Override
public void sendReplay(
@Nullable Boolean isCrashed, @Nullable String eventId, @Nullable Hint hint) {}

@Override
public @NotNull SentryId getReplayId() {
return SentryId.EMPTY_ID;
Expand Down
3 changes: 3 additions & 0 deletions sentry/src/main/java/io/sentry/ReplayController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.sentry.protocol.SentryId;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@ApiStatus.Internal
public interface ReplayController {
Expand All @@ -18,6 +19,8 @@ public interface ReplayController {

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

void sendReplay(@Nullable Boolean isCrashed, @Nullable String eventId, @Nullable Hint hint);

@NotNull
SentryId getReplayId();
}
Loading