Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- Add a `isEnableSystemEventBreadcrumbsExtras` option to disable reporting system events extras for breadcrumbs ([#4625](https://github.com/getsentry/sentry-java/pull/4625))

### Improvements

- Session Replay: Use main thread looper to schedule replay capture ([#4542](https://github.com/getsentry/sentry-java/pull/4542))
Expand Down
2 changes: 2 additions & 0 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun isEnableRootCheck ()Z
public fun isEnableScopeSync ()Z
public fun isEnableSystemEventBreadcrumbs ()Z
public fun isEnableSystemEventBreadcrumbsExtras ()Z
public fun isReportHistoricalAnrs ()Z
public fun setAnrEnabled (Z)V
public fun setAnrReportInDebug (Z)V
Expand All @@ -360,6 +361,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun setEnableRootCheck (Z)V
public fun setEnableScopeSync (Z)V
public fun setEnableSystemEventBreadcrumbs (Z)V
public fun setEnableSystemEventBreadcrumbsExtras (Z)V
public fun setFrameMetricsCollector (Lio/sentry/android/core/internal/util/SentryFrameMetricsCollector;)V
public fun setNativeHandlerStrategy (Lio/sentry/android/core/NdkHandlerStrategy;)V
public fun setNativeSdkName (Ljava/lang/String;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ public final class SentryAndroidOptions extends SentryOptions {
*/
private boolean enableAutoTraceIdGeneration = true;

/** Enable or disable intent extras reporting for system event breadcrumbs. Default is false. */
private boolean enableSystemEventBreadcrumbsExtras = false;

public interface BeforeCaptureCallback {

/**
Expand Down Expand Up @@ -614,6 +617,15 @@ public void setEnableAutoTraceIdGeneration(final boolean enableAutoTraceIdGenera
this.enableAutoTraceIdGeneration = enableAutoTraceIdGeneration;
}

public boolean isEnableSystemEventBreadcrumbsExtras() {
return enableSystemEventBreadcrumbsExtras;
}

public void setEnableSystemEventBreadcrumbsExtras(
final boolean enableSystemEventBreadcrumbsExtras) {
this.enableSystemEventBreadcrumbsExtras = enableSystemEventBreadcrumbsExtras;
}

static class AndroidUserFeedbackIDialogHandler implements SentryFeedbackOptions.IDialogHandler {
@Override
public void showDialog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ String getStringAfterDotFast(final @Nullable String str) {
if (batteryState.charging != null) {
breadcrumb.setData("charging", batteryState.charging);
}
} else {
} else if (options.isEnableSystemEventBreadcrumbsExtras()) {
final Bundle extras = intent.getExtras();
if (extras != null && !extras.isEmpty()) {
final Map<String, String> newExtras = new HashMap<>(extras.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ class SentryAndroidOptionsTest {
)
}

@Test
fun `system event breadcrumbs extras disabled by default`() {
val sentryOptions = SentryAndroidOptions()

assertFalse(sentryOptions.isEnableSystemEventBreadcrumbsExtras)
}

@Test
fun `system event breadcrumbs extras can be enabled`() {
val sentryOptions = SentryAndroidOptions()
sentryOptions.isEnableSystemEventBreadcrumbsExtras = true
assertTrue(sentryOptions.isEnableSystemEventBreadcrumbsExtras)
}

private class CustomDebugImagesLoader : IDebugImagesLoader {
override fun loadDebugImages(): List<DebugImage>? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ class SystemEventsBreadcrumbsIntegrationTest {

fun getSut(
enableSystemEventBreadcrumbs: Boolean = true,
enableSystemEventBreadcrumbsExtras: Boolean = false,
executorService: ISentryExecutorService = ImmediateExecutorService(),
): SystemEventsBreadcrumbsIntegration {
options =
SentryAndroidOptions().apply {
isEnableSystemEventBreadcrumbs = enableSystemEventBreadcrumbs
isEnableSystemEventBreadcrumbsExtras = enableSystemEventBreadcrumbsExtras
this.executorService = executorService
}
return SystemEventsBreadcrumbsIntegration(
Expand Down Expand Up @@ -528,4 +530,59 @@ class SystemEventsBreadcrumbsIntegrationTest {

assertNull(sut.receiver)
}

@Test
fun `system event breadcrumbs include extras when enableSystemEventBreadcrumbsExtras is true`() {
val sut = fixture.getSut(enableSystemEventBreadcrumbsExtras = true)

sut.register(fixture.scopes, fixture.options)
val intent =
Intent().apply {
action = Intent.ACTION_TIME_CHANGED
putExtra("test", 10)
putExtra("test2", 20)
}
sut.receiver!!.onReceive(fixture.context, intent)

verify(fixture.scopes)
.addBreadcrumb(
check<Breadcrumb> {
assertEquals("device.event", it.category)
assertEquals("system", it.type)
assertEquals(SentryLevel.INFO, it.level)
assertEquals("TIME_SET", it.data["action"])
assertNotNull(it.data["extras"])
val extras = it.data["extras"] as Map<String, String>
assertEquals("10", extras["test"])
assertEquals("20", extras["test2"])
},
anyOrNull(),
)
}

@Test
fun `system event breadcrumbs do not include extras when enableSystemEventBreadcrumbsExtras is false`() {
val sut = fixture.getSut(enableSystemEventBreadcrumbsExtras = false)

sut.register(fixture.scopes, fixture.options)
val intent =
Intent().apply {
action = Intent.ACTION_TIME_CHANGED
putExtra("test", 10)
putExtra("test2", 20)
}
sut.receiver!!.onReceive(fixture.context, intent)

verify(fixture.scopes)
.addBreadcrumb(
check<Breadcrumb> {
assertEquals("device.event", it.category)
assertEquals("system", it.type)
assertEquals(SentryLevel.INFO, it.level)
assertEquals("TIME_SET", it.data["action"])
assertNull(it.data["extras"])
},
anyOrNull(),
)
}
}
Loading