Skip to content

Commit 73a2923

Browse files
authored
chore(breadcrumbs): Add an option to disable reporting system events extras for breadcrumbs (#4625)
1 parent 5625283 commit 73a2923

File tree

6 files changed

+90
-1
lines changed

6 files changed

+90
-1
lines changed

CHANGELOG.md

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

33
## Unreleased
44

5+
### Features
6+
7+
- Add a `isEnableSystemEventBreadcrumbsExtras` option to disable reporting system events extras for breadcrumbs ([#4625](https://github.com/getsentry/sentry-java/pull/4625))
8+
59
### Improvements
610

711
- Session Replay: Use main thread looper to schedule replay capture ([#4542](https://github.com/getsentry/sentry-java/pull/4542))

sentry-android-core/api/sentry-android-core.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
336336
public fun isEnableRootCheck ()Z
337337
public fun isEnableScopeSync ()Z
338338
public fun isEnableSystemEventBreadcrumbs ()Z
339+
public fun isEnableSystemEventBreadcrumbsExtras ()Z
339340
public fun isReportHistoricalAnrs ()Z
340341
public fun setAnrEnabled (Z)V
341342
public fun setAnrReportInDebug (Z)V
@@ -360,6 +361,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
360361
public fun setEnableRootCheck (Z)V
361362
public fun setEnableScopeSync (Z)V
362363
public fun setEnableSystemEventBreadcrumbs (Z)V
364+
public fun setEnableSystemEventBreadcrumbsExtras (Z)V
363365
public fun setFrameMetricsCollector (Lio/sentry/android/core/internal/util/SentryFrameMetricsCollector;)V
364366
public fun setNativeHandlerStrategy (Lio/sentry/android/core/NdkHandlerStrategy;)V
365367
public fun setNativeSdkName (Ljava/lang/String;)V

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ public final class SentryAndroidOptions extends SentryOptions {
177177
*/
178178
private boolean enableAutoTraceIdGeneration = true;
179179

180+
/** Enable or disable intent extras reporting for system event breadcrumbs. Default is false. */
181+
private boolean enableSystemEventBreadcrumbsExtras = false;
182+
180183
public interface BeforeCaptureCallback {
181184

182185
/**
@@ -614,6 +617,15 @@ public void setEnableAutoTraceIdGeneration(final boolean enableAutoTraceIdGenera
614617
this.enableAutoTraceIdGeneration = enableAutoTraceIdGeneration;
615618
}
616619

620+
public boolean isEnableSystemEventBreadcrumbsExtras() {
621+
return enableSystemEventBreadcrumbsExtras;
622+
}
623+
624+
public void setEnableSystemEventBreadcrumbsExtras(
625+
final boolean enableSystemEventBreadcrumbsExtras) {
626+
this.enableSystemEventBreadcrumbsExtras = enableSystemEventBreadcrumbsExtras;
627+
}
628+
617629
static class AndroidUserFeedbackIDialogHandler implements SentryFeedbackOptions.IDialogHandler {
618630
@Override
619631
public void showDialog(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ String getStringAfterDotFast(final @Nullable String str) {
370370
if (batteryState.charging != null) {
371371
breadcrumb.setData("charging", batteryState.charging);
372372
}
373-
} else {
373+
} else if (options.isEnableSystemEventBreadcrumbsExtras()) {
374374
final Bundle extras = intent.getExtras();
375375
if (extras != null && !extras.isEmpty()) {
376376
final Map<String, String> newExtras = new HashMap<>(extras.size());

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,20 @@ class SentryAndroidOptionsTest {
181181
)
182182
}
183183

184+
@Test
185+
fun `system event breadcrumbs extras disabled by default`() {
186+
val sentryOptions = SentryAndroidOptions()
187+
188+
assertFalse(sentryOptions.isEnableSystemEventBreadcrumbsExtras)
189+
}
190+
191+
@Test
192+
fun `system event breadcrumbs extras can be enabled`() {
193+
val sentryOptions = SentryAndroidOptions()
194+
sentryOptions.isEnableSystemEventBreadcrumbsExtras = true
195+
assertTrue(sentryOptions.isEnableSystemEventBreadcrumbsExtras)
196+
}
197+
184198
private class CustomDebugImagesLoader : IDebugImagesLoader {
185199
override fun loadDebugImages(): List<DebugImage>? = null
186200

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ class SystemEventsBreadcrumbsIntegrationTest {
5151

5252
fun getSut(
5353
enableSystemEventBreadcrumbs: Boolean = true,
54+
enableSystemEventBreadcrumbsExtras: Boolean = false,
5455
executorService: ISentryExecutorService = ImmediateExecutorService(),
5556
): SystemEventsBreadcrumbsIntegration {
5657
options =
5758
SentryAndroidOptions().apply {
5859
isEnableSystemEventBreadcrumbs = enableSystemEventBreadcrumbs
60+
isEnableSystemEventBreadcrumbsExtras = enableSystemEventBreadcrumbsExtras
5961
this.executorService = executorService
6062
}
6163
return SystemEventsBreadcrumbsIntegration(
@@ -528,4 +530,59 @@ class SystemEventsBreadcrumbsIntegrationTest {
528530

529531
assertNull(sut.receiver)
530532
}
533+
534+
@Test
535+
fun `system event breadcrumbs include extras when enableSystemEventBreadcrumbsExtras is true`() {
536+
val sut = fixture.getSut(enableSystemEventBreadcrumbsExtras = true)
537+
538+
sut.register(fixture.scopes, fixture.options)
539+
val intent =
540+
Intent().apply {
541+
action = Intent.ACTION_TIME_CHANGED
542+
putExtra("test", 10)
543+
putExtra("test2", 20)
544+
}
545+
sut.receiver!!.onReceive(fixture.context, intent)
546+
547+
verify(fixture.scopes)
548+
.addBreadcrumb(
549+
check<Breadcrumb> {
550+
assertEquals("device.event", it.category)
551+
assertEquals("system", it.type)
552+
assertEquals(SentryLevel.INFO, it.level)
553+
assertEquals("TIME_SET", it.data["action"])
554+
assertNotNull(it.data["extras"])
555+
val extras = it.data["extras"] as Map<String, String>
556+
assertEquals("10", extras["test"])
557+
assertEquals("20", extras["test2"])
558+
},
559+
anyOrNull(),
560+
)
561+
}
562+
563+
@Test
564+
fun `system event breadcrumbs do not include extras when enableSystemEventBreadcrumbsExtras is false`() {
565+
val sut = fixture.getSut(enableSystemEventBreadcrumbsExtras = false)
566+
567+
sut.register(fixture.scopes, fixture.options)
568+
val intent =
569+
Intent().apply {
570+
action = Intent.ACTION_TIME_CHANGED
571+
putExtra("test", 10)
572+
putExtra("test2", 20)
573+
}
574+
sut.receiver!!.onReceive(fixture.context, intent)
575+
576+
verify(fixture.scopes)
577+
.addBreadcrumb(
578+
check<Breadcrumb> {
579+
assertEquals("device.event", it.category)
580+
assertEquals("system", it.type)
581+
assertEquals(SentryLevel.INFO, it.level)
582+
assertEquals("TIME_SET", it.data["action"])
583+
assertNull(it.data["extras"])
584+
},
585+
anyOrNull(),
586+
)
587+
}
531588
}

0 commit comments

Comments
 (0)