Skip to content

Commit

Permalink
Add AndroidManifest options for replays
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn committed Mar 26, 2024
1 parent 7854e4f commit 2cddcc4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ final class ManifestMetadataReader {

static final String ENABLE_APP_START_PROFILING = "io.sentry.profiling.enable-app-start";

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

static final String REPLAYS_ERROR_SAMPLE_RATE = "io.sentry.replays.error-sample-rate";

/** ManifestMetadataReader ctor */
private ManifestMetadataReader() {}

Expand Down Expand Up @@ -371,6 +375,21 @@ static void applyMetadata(
options.setEnableAppStartProfiling(
readBool(
metadata, logger, ENABLE_APP_START_PROFILING, options.isEnableAppStartProfiling()));

if (options.get_experimental().getReplayOptions().getSessionSampleRate() == null) {
final Double sessionSampleRate =
readDouble(metadata, logger, REPLAYS_SESSION_SAMPLE_RATE);
if (sessionSampleRate != -1) {
options.get_experimental().getReplayOptions().setSessionSampleRate(sessionSampleRate);
}
}

if (options.get_experimental().getReplayOptions().getErrorSampleRate() == null) {
final Double errorSampleRate = readDouble(metadata, logger, REPLAYS_ERROR_SAMPLE_RATE);
if (errorSampleRate != -1) {
options.get_experimental().getReplayOptions().setErrorSampleRate(errorSampleRate);
}
}
}

options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1370,4 +1370,46 @@ class ManifestMetadataReaderTest {
// Assert
assertFalse(fixture.options.isEnableAppStartProfiling)
}

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

val bundle = bundleOf(ManifestMetadataReader.REPLAYS_ERROR_SAMPLE_RATE to expectedSampleRate)
val context = fixture.getContext(metaData = bundle)

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

// Assert
assertEquals(expectedSampleRate.toDouble(), fixture.options._experimental.replayOptions.errorSampleRate)
}

@Test
fun `applyMetadata does not override replays errorSampleRate from options`() {
// Arrange
val expectedSampleRate = 0.99f
fixture.options._experimental.replayOptions.errorSampleRate = 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.replayOptions.errorSampleRate)
}

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

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

// Assert
assertNull(fixture.options._experimental.replayOptions.errorSampleRate)
}
}

0 comments on commit 2cddcc4

Please sign in to comment.