Skip to content

Commit

Permalink
Merge branch 'main' into feat/async-ndk-loadlib
Browse files Browse the repository at this point in the history
  • Loading branch information
markushi authored Sep 3, 2024
2 parents 702e93e + 014dbef commit 6fceb9c
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 38 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

*Breaking changes*:

- `options.experimental.sessionReplay.errorSampleRate` was renamed to `options.experimental.sessionReplay.onErrorSampleRate` ([#3637](https://github.com/getsentry/sentry-java/pull/3637))
- Manifest option `io.sentry.session-replay.error-sample-rate` was renamed to `io.sentry.session-replay.on-error-sample-rate` ([#3637](https://github.com/getsentry/sentry-java/pull/3637))

### Features

- Offload System.loadLibrary calls to background thread ([#3670](https://github.com/getsentry/sentry-java/pull/3670))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ final class ManifestMetadataReader {

static final String REPLAYS_SESSION_SAMPLE_RATE = "io.sentry.session-replay.session-sample-rate";

static final String REPLAYS_ERROR_SAMPLE_RATE = "io.sentry.session-replay.error-sample-rate";
static final String REPLAYS_ERROR_SAMPLE_RATE = "io.sentry.session-replay.on-error-sample-rate";

static final String REPLAYS_REDACT_ALL_TEXT = "io.sentry.session-replay.redact-all-text";

Expand Down Expand Up @@ -399,10 +399,10 @@ static void applyMetadata(
}
}

if (options.getExperimental().getSessionReplay().getErrorSampleRate() == null) {
final Double errorSampleRate = readDouble(metadata, logger, REPLAYS_ERROR_SAMPLE_RATE);
if (errorSampleRate != -1) {
options.getExperimental().getSessionReplay().setErrorSampleRate(errorSampleRate);
if (options.getExperimental().getSessionReplay().getOnErrorSampleRate() == null) {
final Double onErrorSampleRate = readDouble(metadata, logger, REPLAYS_ERROR_SAMPLE_RATE);
if (onErrorSampleRate != -1) {
options.getExperimental().getSessionReplay().setOnErrorSampleRate(onErrorSampleRate);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ class ManifestMetadataReaderTest {
}

@Test
fun `applyMetadata reads replays errorSampleRate from metadata`() {
fun `applyMetadata reads replays onErrorSampleRate from metadata`() {
// Arrange
val expectedSampleRate = 0.99f

Expand All @@ -1433,34 +1433,34 @@ class ManifestMetadataReaderTest {
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)

// Assert
assertEquals(expectedSampleRate.toDouble(), fixture.options.experimental.sessionReplay.errorSampleRate)
assertEquals(expectedSampleRate.toDouble(), fixture.options.experimental.sessionReplay.onErrorSampleRate)
}

@Test
fun `applyMetadata does not override replays errorSampleRate from options`() {
fun `applyMetadata does not override replays onErrorSampleRate from options`() {
// Arrange
val expectedSampleRate = 0.99f
fixture.options.experimental.sessionReplay.errorSampleRate = expectedSampleRate.toDouble()
fixture.options.experimental.sessionReplay.onErrorSampleRate = expectedSampleRate.toDouble()
val bundle = bundleOf(ManifestMetadataReader.REPLAYS_ERROR_SAMPLE_RATE to 0.1f)
val context = fixture.getContext(metaData = bundle)

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)

// Assert
assertEquals(expectedSampleRate.toDouble(), fixture.options.experimental.sessionReplay.errorSampleRate)
assertEquals(expectedSampleRate.toDouble(), fixture.options.experimental.sessionReplay.onErrorSampleRate)
}

@Test
fun `applyMetadata without specifying replays errorSampleRate, stays null`() {
fun `applyMetadata without specifying replays onErrorSampleRate, stays null`() {
// Arrange
val context = fixture.getContext()

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)

// Assert
assertNull(fixture.options.experimental.sessionReplay.errorSampleRate)
assertNull(fixture.options.experimental.sessionReplay.onErrorSampleRate)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class SentryAndroidTest {
options.release = "prod"
options.dsn = "https://[email protected]/123"
options.isEnableAutoSessionTracking = true
options.experimental.sessionReplay.errorSampleRate = 1.0
options.experimental.sessionReplay.onErrorSampleRate = 1.0
optionsConfig(options)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public class ReplayIntegration(

val isFullSession = random.sample(options.experimental.sessionReplay.sessionSampleRate)
if (!isFullSession && !options.experimental.sessionReplay.isSessionReplayForErrorsEnabled) {
options.logger.log(INFO, "Session replay is not started, full session was not sampled and errorSampleRate is not specified")
options.logger.log(INFO, "Session replay is not started, full session was not sampled and onErrorSampleRate is not specified")
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ internal class BufferCaptureStrategy(
isTerminating: Boolean,
onSegmentSent: (Date) -> Unit
) {
val sampled = random.sample(options.experimental.sessionReplay.errorSampleRate)
val sampled = random.sample(options.experimental.sessionReplay.onErrorSampleRate)

if (!sampled) {
options.logger.log(INFO, "Replay wasn't sampled by errorSampleRate, not capturing for event")
options.logger.log(INFO, "Replay wasn't sampled by onErrorSampleRate, not capturing for event")
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class AnrWithReplayIntegrationTest {
it.cacheDirPath = cacheDir
it.isDebug = true
it.setLogger(SystemOutLogger())
it.experimental.sessionReplay.errorSampleRate = 1.0
it.experimental.sessionReplay.onErrorSampleRate = 1.0
// beforeSend is called after event processors are applied, so we can assert here
// against the enriched ANR event
it.beforeSend = SentryOptions.BeforeSendCallback { event, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ class ReplayIntegrationTest {
fun getSut(
context: Context,
sessionSampleRate: Double = 1.0,
errorSampleRate: Double = 1.0,
onErrorSampleRate: Double = 1.0,
recorderProvider: (() -> Recorder)? = null,
replayCaptureStrategyProvider: ((isFullSession: Boolean) -> CaptureStrategy)? = null,
recorderConfigProvider: ((configChanged: Boolean) -> ScreenshotRecorderConfig)? = null,
gestureRecorderProvider: (() -> GestureRecorder)? = null,
dateProvider: ICurrentDateProvider = CurrentDateProvider.getInstance()
): ReplayIntegration {
options.run {
experimental.sessionReplay.errorSampleRate = errorSampleRate
experimental.sessionReplay.onErrorSampleRate = onErrorSampleRate
experimental.sessionReplay.sessionSampleRate = sessionSampleRate
}
return ReplayIntegration(
Expand Down Expand Up @@ -204,7 +204,7 @@ class ReplayIntegrationTest {
@Test
fun `does not start replay when session is not sampled`() {
val captureStrategy = mock<CaptureStrategy>()
val replay = fixture.getSut(context, errorSampleRate = 0.0, sessionSampleRate = 0.0, replayCaptureStrategyProvider = { captureStrategy })
val replay = fixture.getSut(context, onErrorSampleRate = 0.0, sessionSampleRate = 0.0, replayCaptureStrategyProvider = { captureStrategy })

replay.register(fixture.hub, fixture.options)
replay.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class ReplaySmokeTest {
captured.set(true)
}

fixture.options.experimental.sessionReplay.errorSampleRate = 1.0
fixture.options.experimental.sessionReplay.onErrorSampleRate = 1.0
fixture.options.cacheDirPath = tmpDir.newFolder().absolutePath

val replay: ReplayIntegration = fixture.getSut(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ class BufferCaptureStrategyTest {
)

fun getSut(
errorSampleRate: Double = 1.0,
onErrorSampleRate: Double = 1.0,
dateProvider: ICurrentDateProvider = CurrentDateProvider.getInstance(),
replayCacheDir: File? = null
): BufferCaptureStrategy {
replayCacheDir?.let {
whenever(replayCache.replayCacheDir).thenReturn(it)
}
options.run {
experimental.sessionReplay.errorSampleRate = errorSampleRate
experimental.sessionReplay.onErrorSampleRate = onErrorSampleRate
}
return BufferCaptureStrategy(
options,
Expand Down Expand Up @@ -256,7 +256,7 @@ class BufferCaptureStrategyTest {

@Test
fun `captureReplay does not replayId to scope when not sampled`() {
val strategy = fixture.getSut(errorSampleRate = 0.0)
val strategy = fixture.getSut(onErrorSampleRate = 0.0)
strategy.start(fixture.recorderConfig)

strategy.captureReplay(false) {}
Expand Down
4 changes: 2 additions & 2 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -2703,8 +2703,8 @@ public final class io/sentry/SentryReplayOptions {
public fun <init> (Ljava/lang/Double;Ljava/lang/Double;)V
public fun addClassToRedact (Ljava/lang/String;)V
public fun getErrorReplayDuration ()J
public fun getErrorSampleRate ()Ljava/lang/Double;
public fun getFrameRate ()I
public fun getOnErrorSampleRate ()Ljava/lang/Double;
public fun getQuality ()Lio/sentry/SentryReplayOptions$SentryReplayQuality;
public fun getRedactAllImages ()Z
public fun getRedactAllText ()Z
Expand All @@ -2714,7 +2714,7 @@ public final class io/sentry/SentryReplayOptions {
public fun getSessionSegmentDuration ()J
public fun isSessionReplayEnabled ()Z
public fun isSessionReplayForErrorsEnabled ()Z
public fun setErrorSampleRate (Ljava/lang/Double;)V
public fun setOnErrorSampleRate (Ljava/lang/Double;)V
public fun setQuality (Lio/sentry/SentryReplayOptions$SentryReplayQuality;)V
public fun setRedactAllImages (Z)V
public fun setRedactAllText (Z)V
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private static void notifyOptionsObservers(final @NotNull SentryOptions options)
observer.setEnvironment(options.getEnvironment());
observer.setTags(options.getTags());
observer.setReplayErrorSampleRate(
options.getExperimental().getSessionReplay().getErrorSampleRate());
options.getExperimental().getSessionReplay().getOnErrorSampleRate());
}
});
} catch (Throwable e) {
Expand Down
20 changes: 10 additions & 10 deletions sentry/src/main/java/io/sentry/SentryReplayOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum SentryReplayQuality {
* Specifying 0 means never, 1.0 means always. The value needs to be >= 0.0 and <= 1.0. The
* default is null (disabled).
*/
private @Nullable Double errorSampleRate;
private @Nullable Double onErrorSampleRate;

/**
* Redact all text content. Draws a rectangle of text bounds with text color on top. By default
Expand Down Expand Up @@ -98,28 +98,28 @@ public enum SentryReplayQuality {
public SentryReplayOptions() {}

public SentryReplayOptions(
final @Nullable Double sessionSampleRate, final @Nullable Double errorSampleRate) {
final @Nullable Double sessionSampleRate, final @Nullable Double onErrorSampleRate) {
this.sessionSampleRate = sessionSampleRate;
this.errorSampleRate = errorSampleRate;
this.onErrorSampleRate = onErrorSampleRate;
}

@Nullable
public Double getErrorSampleRate() {
return errorSampleRate;
public Double getOnErrorSampleRate() {
return onErrorSampleRate;
}

public boolean isSessionReplayEnabled() {
return (getSessionSampleRate() != null && getSessionSampleRate() > 0);
}

public void setErrorSampleRate(final @Nullable Double errorSampleRate) {
if (!SampleRateUtils.isValidSampleRate(errorSampleRate)) {
public void setOnErrorSampleRate(final @Nullable Double onErrorSampleRate) {
if (!SampleRateUtils.isValidSampleRate(onErrorSampleRate)) {
throw new IllegalArgumentException(
"The value "
+ errorSampleRate
+ onErrorSampleRate
+ " is not valid. Use null to disable or values >= 0.0 and <= 1.0.");
}
this.errorSampleRate = errorSampleRate;
this.onErrorSampleRate = onErrorSampleRate;
}

@Nullable
Expand All @@ -128,7 +128,7 @@ public Double getSessionSampleRate() {
}

public boolean isSessionReplayForErrorsEnabled() {
return (getErrorSampleRate() != null && getErrorSampleRate() > 0);
return (getOnErrorSampleRate() != null && getOnErrorSampleRate() > 0);
}

public void setSessionSampleRate(final @Nullable Double sessionSampleRate) {
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/test/java/io/sentry/SentryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ class SentryTest {
it.sdkVersion = SdkVersion("sentry.java.android", "6.13.0")
it.environment = "debug"
it.setTag("one", "two")
it.experimental.sessionReplay.errorSampleRate = 0.5
it.experimental.sessionReplay.onErrorSampleRate = 0.5
}

assertEquals("[email protected]+220", optionsObserver.release)
Expand Down

0 comments on commit 6fceb9c

Please sign in to comment.