Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
expose max-breadcrumbs on meta data and implement disabled queue when…
… maxbreadcrumbs sets to 0
  • Loading branch information
Lucas committed Oct 30, 2024
commit d282d06f5b75971bdc3ee3e4c5d01ff5438d7b71
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## Unreleased

### Features

- Add meta option to set the maximum amount of breadcrumbs to be logged. ([#?](https://github.com/getsentry/sentry-java/pull/?))


### Fixes

- using MaxBreadcrumb with value 0 no longer crashes. ([#?](https://github.com/getsentry/sentry-java/pull/?))

## 7.16.0

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ final class ManifestMetadataReader {

static final String ENABLE_METRICS = "io.sentry.enable-metrics";

static final String MAX_BREADCRUMBS = "io.sentry.max-breadcrumbs";

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.on-error-sample-rate";
Expand Down Expand Up @@ -213,6 +215,13 @@ static void applyMetadata(
SESSION_TRACKING_TIMEOUT_INTERVAL_MILLIS,
options.getSessionTrackingIntervalMillis()));

options.setMaxBreadcrumbs(
(int)readLong(
metadata,
logger,
MAX_BREADCRUMBS,
options.getMaxBreadcrumbs()));

options.setEnableActivityLifecycleBreadcrumbs(
readBool(
metadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1515,4 +1515,30 @@ class ManifestMetadataReaderTest {
assertTrue(fixture.options.experimental.sessionReplay.maskViewClasses.contains(SentryReplayOptions.IMAGE_VIEW_CLASS_NAME))
assertTrue(fixture.options.experimental.sessionReplay.maskViewClasses.contains(SentryReplayOptions.TEXT_VIEW_CLASS_NAME))
}

@Test
fun `applyMetadata reads maxbreadcrumb mask flags to options and sets the value if found`() {
// Arrange
val bundle = bundleOf(ManifestMetadataReader.MAX_BREADCRUMBS to 1)
val context = fixture.getContext(metaData = bundle)

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

// Assert
assertEquals(1, fixture.options.maxBreadcrumbs)
}

@Test
fun `applyMetadata reads max breadcrumb mask flags to options and keeps default if not found`() {
// Arrange
val context = fixture.getContext()

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

// Assert
assertEquals(100, fixture.options.maxBreadcrumbs)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@
<!-- how to enable the attach screenshot feature-->
<meta-data android:name="io.sentry.attach-screenshot" android:value="true" />

<!-- how many breadcrumbs will be stored-->
<meta-data android:name="io.sentry.max-breadcrumbs" android:value="100"/>

<!-- how to enable the attach view hierarchy feature-->
<meta-data android:name="io.sentry.attach-view-hierarchy" android:value="true" />

Expand Down
4 changes: 3 additions & 1 deletion sentry/src/main/java/io/sentry/Scope.java
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,9 @@ public void clearAttachments() {
* @return the breadcrumbs queue
*/
private @NotNull Queue<Breadcrumb> createBreadcrumbsList(final int maxBreadcrumb) {
return SynchronizedQueue.synchronizedQueue(new CircularFifoQueue<>(maxBreadcrumb));
return maxBreadcrumb > 0 ?
SynchronizedQueue.synchronizedQueue(new CircularFifoQueue<>(maxBreadcrumb)) :
SynchronizedQueue.synchronizedQueue(new DisabledQueue<>());
}

/**
Expand Down
11 changes: 11 additions & 0 deletions sentry/src/test/java/io/sentry/ScopeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,17 @@ class ScopeTest {
)
}

@Test
fun `creating a new scope won't crash if max breadcrumbs is set to zero`() {
val options = SentryOptions().apply {
maxBreadcrumbs = 0
}
val scope = Scope(options)

// expect no exception to be thrown
// previously was crashing, see https://github.com/getsentry/sentry-java/issues/3313
}

private fun eventProcessor(): EventProcessor {
return object : EventProcessor {
override fun process(event: SentryEvent, hint: Hint): SentryEvent? {
Expand Down