Skip to content

Commit f80f33e

Browse files
authored
Merge branch 'main' into fix/activity-leak
2 parents 2252e62 + 70d1da1 commit f80f33e

File tree

17 files changed

+67
-43
lines changed

17 files changed

+67
-43
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44

55
### Fixes
66

7+
- Avoid stopping appStartProfiler after application creation ([#3630](https://github.com/getsentry/sentry-java/pull/3630))
78
- Fix ensure Application Context is used even when SDK is initialized via Activity Context ([#3669](https://github.com/getsentry/sentry-java/pull/3669))
89

10+
*Breaking changes*:
11+
12+
- `options.experimental.sessionReplay.errorSampleRate` was renamed to `options.experimental.sessionReplay.onErrorSampleRate` ([#3637](https://github.com/getsentry/sentry-java/pull/3637))
13+
- 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))
14+
915
## 7.14.0
1016

1117
### Features

sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ final class ManifestMetadataReader {
106106

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

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

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

@@ -399,10 +399,10 @@ static void applyMetadata(
399399
}
400400
}
401401

402-
if (options.getExperimental().getSessionReplay().getErrorSampleRate() == null) {
403-
final Double errorSampleRate = readDouble(metadata, logger, REPLAYS_ERROR_SAMPLE_RATE);
404-
if (errorSampleRate != -1) {
405-
options.getExperimental().getSessionReplay().setErrorSampleRate(errorSampleRate);
402+
if (options.getExperimental().getSessionReplay().getOnErrorSampleRate() == null) {
403+
final Double onErrorSampleRate = readDouble(metadata, logger, REPLAYS_ERROR_SAMPLE_RATE);
404+
if (onErrorSampleRate != -1) {
405+
options.getExperimental().getSessionReplay().setOnErrorSampleRate(onErrorSampleRate);
406406
}
407407
}
408408

sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,14 @@ private void checkCreateTimeOnMain(final @NotNull Application application) {
255255
// if no activity has ever been created, app was launched in background
256256
if (onCreateTime == null) {
257257
appLaunchedInForeground = false;
258+
259+
// we stop the app start profiler, as it's useless and likely to timeout
260+
if (appStartProfiler != null && appStartProfiler.isRunning()) {
261+
appStartProfiler.close();
262+
appStartProfiler = null;
263+
}
258264
}
259265
application.unregisterActivityLifecycleCallbacks(instance);
260-
// we stop the app start profiler, as it's useless and likely to timeout
261-
if (appStartProfiler != null && appStartProfiler.isRunning()) {
262-
appStartProfiler.close();
263-
appStartProfiler = null;
264-
}
265266
});
266267
}
267268

sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ class ManifestMetadataReaderTest {
14221422
}
14231423

14241424
@Test
1425-
fun `applyMetadata reads replays errorSampleRate from metadata`() {
1425+
fun `applyMetadata reads replays onErrorSampleRate from metadata`() {
14261426
// Arrange
14271427
val expectedSampleRate = 0.99f
14281428

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

14351435
// Assert
1436-
assertEquals(expectedSampleRate.toDouble(), fixture.options.experimental.sessionReplay.errorSampleRate)
1436+
assertEquals(expectedSampleRate.toDouble(), fixture.options.experimental.sessionReplay.onErrorSampleRate)
14371437
}
14381438

14391439
@Test
1440-
fun `applyMetadata does not override replays errorSampleRate from options`() {
1440+
fun `applyMetadata does not override replays onErrorSampleRate from options`() {
14411441
// Arrange
14421442
val expectedSampleRate = 0.99f
1443-
fixture.options.experimental.sessionReplay.errorSampleRate = expectedSampleRate.toDouble()
1443+
fixture.options.experimental.sessionReplay.onErrorSampleRate = expectedSampleRate.toDouble()
14441444
val bundle = bundleOf(ManifestMetadataReader.REPLAYS_ERROR_SAMPLE_RATE to 0.1f)
14451445
val context = fixture.getContext(metaData = bundle)
14461446

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

14501450
// Assert
1451-
assertEquals(expectedSampleRate.toDouble(), fixture.options.experimental.sessionReplay.errorSampleRate)
1451+
assertEquals(expectedSampleRate.toDouble(), fixture.options.experimental.sessionReplay.onErrorSampleRate)
14521452
}
14531453

14541454
@Test
1455-
fun `applyMetadata without specifying replays errorSampleRate, stays null`() {
1455+
fun `applyMetadata without specifying replays onErrorSampleRate, stays null`() {
14561456
// Arrange
14571457
val context = fixture.getContext()
14581458

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

14621462
// Assert
1463-
assertNull(fixture.options.experimental.sessionReplay.errorSampleRate)
1463+
assertNull(fixture.options.experimental.sessionReplay.onErrorSampleRate)
14641464
}
14651465

14661466
@Test

sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class SentryAndroidTest {
369369
options.release = "prod"
370370
options.dsn = "https://[email protected]/123"
371371
options.isEnableAutoSessionTracking = true
372-
options.experimental.sessionReplay.errorSampleRate = 1.0
372+
options.experimental.sessionReplay.onErrorSampleRate = 1.0
373373
optionsConfig(options)
374374
}
375375

sentry-android-core/src/test/java/io/sentry/android/core/performance/AppStartMetricsTest.kt

+14
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ class AppStartMetricsTest {
196196
verify(profiler).close()
197197
}
198198

199+
@Test
200+
fun `if activity is started, does not stop app start profiler if running`() {
201+
val profiler = mock<ITransactionProfiler>()
202+
whenever(profiler.isRunning).thenReturn(true)
203+
AppStartMetrics.getInstance().appStartProfiler = profiler
204+
AppStartMetrics.getInstance().onActivityCreated(mock(), mock())
205+
206+
AppStartMetrics.getInstance().registerApplicationForegroundCheck(mock())
207+
// Job on main thread checks if activity was launched
208+
Shadows.shadowOf(Looper.getMainLooper()).idle()
209+
210+
verify(profiler, never()).close()
211+
}
212+
199213
@Test
200214
fun `if app start span is longer than 1 minute, appStartTimeSpanWithFallback returns an empty span`() {
201215
val appStartTimeSpan = AppStartMetrics.getInstance().appStartTimeSpan

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public class ReplayIntegration(
144144

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ internal class BufferCaptureStrategy(
6363
isTerminating: Boolean,
6464
onSegmentSent: (Date) -> Unit
6565
) {
66-
val sampled = random.sample(options.experimental.sessionReplay.errorSampleRate)
66+
val sampled = random.sample(options.experimental.sessionReplay.onErrorSampleRate)
6767

6868
if (!sampled) {
69-
options.logger.log(INFO, "Replay wasn't sampled by errorSampleRate, not capturing for event")
69+
options.logger.log(INFO, "Replay wasn't sampled by onErrorSampleRate, not capturing for event")
7070
return
7171
}
7272

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#This is the verification token for the io.sentry:sentry-android-replay SDK.
2+
#Tue Aug 20 03:48:30 PDT 2024
3+
token=MNMM3TDLWFC5DOCIOFYQJO7JWI

sentry-android-replay/src/test/java/io/sentry/android/replay/AnrWithReplayIntegrationTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class AnrWithReplayIntegrationTest {
151151
it.cacheDirPath = cacheDir
152152
it.isDebug = true
153153
it.setLogger(SystemOutLogger())
154-
it.experimental.sessionReplay.errorSampleRate = 1.0
154+
it.experimental.sessionReplay.onErrorSampleRate = 1.0
155155
// beforeSend is called after event processors are applied, so we can assert here
156156
// against the enriched ANR event
157157
it.beforeSend = SentryOptions.BeforeSendCallback { event, _ ->

sentry-android-replay/src/test/java/io/sentry/android/replay/ReplayIntegrationTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ class ReplayIntegrationTest {
9797
fun getSut(
9898
context: Context,
9999
sessionSampleRate: Double = 1.0,
100-
errorSampleRate: Double = 1.0,
100+
onErrorSampleRate: Double = 1.0,
101101
recorderProvider: (() -> Recorder)? = null,
102102
replayCaptureStrategyProvider: ((isFullSession: Boolean) -> CaptureStrategy)? = null,
103103
recorderConfigProvider: ((configChanged: Boolean) -> ScreenshotRecorderConfig)? = null,
104104
gestureRecorderProvider: (() -> GestureRecorder)? = null,
105105
dateProvider: ICurrentDateProvider = CurrentDateProvider.getInstance()
106106
): ReplayIntegration {
107107
options.run {
108-
experimental.sessionReplay.errorSampleRate = errorSampleRate
108+
experimental.sessionReplay.onErrorSampleRate = onErrorSampleRate
109109
experimental.sessionReplay.sessionSampleRate = sessionSampleRate
110110
}
111111
return ReplayIntegration(
@@ -204,7 +204,7 @@ class ReplayIntegrationTest {
204204
@Test
205205
fun `does not start replay when session is not sampled`() {
206206
val captureStrategy = mock<CaptureStrategy>()
207-
val replay = fixture.getSut(context, errorSampleRate = 0.0, sessionSampleRate = 0.0, replayCaptureStrategyProvider = { captureStrategy })
207+
val replay = fixture.getSut(context, onErrorSampleRate = 0.0, sessionSampleRate = 0.0, replayCaptureStrategyProvider = { captureStrategy })
208208

209209
replay.register(fixture.hub, fixture.options)
210210
replay.start()

sentry-android-replay/src/test/java/io/sentry/android/replay/ReplaySmokeTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class ReplaySmokeTest {
154154
captured.set(true)
155155
}
156156

157-
fixture.options.experimental.sessionReplay.errorSampleRate = 1.0
157+
fixture.options.experimental.sessionReplay.onErrorSampleRate = 1.0
158158
fixture.options.cacheDirPath = tmpDir.newFolder().absolutePath
159159

160160
val replay: ReplayIntegration = fixture.getSut(context)

sentry-android-replay/src/test/java/io/sentry/android/replay/capture/BufferCaptureStrategyTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ class BufferCaptureStrategyTest {
8383
)
8484

8585
fun getSut(
86-
errorSampleRate: Double = 1.0,
86+
onErrorSampleRate: Double = 1.0,
8787
dateProvider: ICurrentDateProvider = CurrentDateProvider.getInstance(),
8888
replayCacheDir: File? = null
8989
): BufferCaptureStrategy {
9090
replayCacheDir?.let {
9191
whenever(replayCache.replayCacheDir).thenReturn(it)
9292
}
9393
options.run {
94-
experimental.sessionReplay.errorSampleRate = errorSampleRate
94+
experimental.sessionReplay.onErrorSampleRate = onErrorSampleRate
9595
}
9696
return BufferCaptureStrategy(
9797
options,
@@ -256,7 +256,7 @@ class BufferCaptureStrategyTest {
256256

257257
@Test
258258
fun `captureReplay does not replayId to scope when not sampled`() {
259-
val strategy = fixture.getSut(errorSampleRate = 0.0)
259+
val strategy = fixture.getSut(onErrorSampleRate = 0.0)
260260
strategy.start(fixture.recorderConfig)
261261

262262
strategy.captureReplay(false) {}

sentry/api/sentry.api

+2-2
Original file line numberDiff line numberDiff line change
@@ -2703,8 +2703,8 @@ public final class io/sentry/SentryReplayOptions {
27032703
public fun <init> (Ljava/lang/Double;Ljava/lang/Double;)V
27042704
public fun addClassToRedact (Ljava/lang/String;)V
27052705
public fun getErrorReplayDuration ()J
2706-
public fun getErrorSampleRate ()Ljava/lang/Double;
27072706
public fun getFrameRate ()I
2707+
public fun getOnErrorSampleRate ()Ljava/lang/Double;
27082708
public fun getQuality ()Lio/sentry/SentryReplayOptions$SentryReplayQuality;
27092709
public fun getRedactAllImages ()Z
27102710
public fun getRedactAllText ()Z
@@ -2714,7 +2714,7 @@ public final class io/sentry/SentryReplayOptions {
27142714
public fun getSessionSegmentDuration ()J
27152715
public fun isSessionReplayEnabled ()Z
27162716
public fun isSessionReplayForErrorsEnabled ()Z
2717-
public fun setErrorSampleRate (Ljava/lang/Double;)V
2717+
public fun setOnErrorSampleRate (Ljava/lang/Double;)V
27182718
public fun setQuality (Lio/sentry/SentryReplayOptions$SentryReplayQuality;)V
27192719
public fun setRedactAllImages (Z)V
27202720
public fun setRedactAllText (Z)V

sentry/src/main/java/io/sentry/Sentry.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ private static void notifyOptionsObservers(final @NotNull SentryOptions options)
357357
observer.setEnvironment(options.getEnvironment());
358358
observer.setTags(options.getTags());
359359
observer.setReplayErrorSampleRate(
360-
options.getExperimental().getSessionReplay().getErrorSampleRate());
360+
options.getExperimental().getSessionReplay().getOnErrorSampleRate());
361361
}
362362
});
363363
} catch (Throwable e) {

sentry/src/main/java/io/sentry/SentryReplayOptions.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public enum SentryReplayQuality {
4646
* Specifying 0 means never, 1.0 means always. The value needs to be >= 0.0 and <= 1.0. The
4747
* default is null (disabled).
4848
*/
49-
private @Nullable Double errorSampleRate;
49+
private @Nullable Double onErrorSampleRate;
5050

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

100100
public SentryReplayOptions(
101-
final @Nullable Double sessionSampleRate, final @Nullable Double errorSampleRate) {
101+
final @Nullable Double sessionSampleRate, final @Nullable Double onErrorSampleRate) {
102102
this.sessionSampleRate = sessionSampleRate;
103-
this.errorSampleRate = errorSampleRate;
103+
this.onErrorSampleRate = onErrorSampleRate;
104104
}
105105

106106
@Nullable
107-
public Double getErrorSampleRate() {
108-
return errorSampleRate;
107+
public Double getOnErrorSampleRate() {
108+
return onErrorSampleRate;
109109
}
110110

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

115-
public void setErrorSampleRate(final @Nullable Double errorSampleRate) {
116-
if (!SampleRateUtils.isValidSampleRate(errorSampleRate)) {
115+
public void setOnErrorSampleRate(final @Nullable Double onErrorSampleRate) {
116+
if (!SampleRateUtils.isValidSampleRate(onErrorSampleRate)) {
117117
throw new IllegalArgumentException(
118118
"The value "
119-
+ errorSampleRate
119+
+ onErrorSampleRate
120120
+ " is not valid. Use null to disable or values >= 0.0 and <= 1.0.");
121121
}
122-
this.errorSampleRate = errorSampleRate;
122+
this.onErrorSampleRate = onErrorSampleRate;
123123
}
124124

125125
@Nullable
@@ -128,7 +128,7 @@ public Double getSessionSampleRate() {
128128
}
129129

130130
public boolean isSessionReplayForErrorsEnabled() {
131-
return (getErrorSampleRate() != null && getErrorSampleRate() > 0);
131+
return (getOnErrorSampleRate() != null && getOnErrorSampleRate() > 0);
132132
}
133133

134134
public void setSessionSampleRate(final @Nullable Double sessionSampleRate) {

sentry/src/test/java/io/sentry/SentryTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ class SentryTest {
737737
it.sdkVersion = SdkVersion("sentry.java.android", "6.13.0")
738738
it.environment = "debug"
739739
it.setTag("one", "two")
740-
it.experimental.sessionReplay.errorSampleRate = 0.5
740+
it.experimental.sessionReplay.onErrorSampleRate = 0.5
741741
}
742742

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

0 commit comments

Comments
 (0)