Skip to content

Commit afe9d2c

Browse files
authored
Fix ignoredErrors, ignoredTransactions and ignoredCheckIns being unset by external options (#4207)
* When parsing ExternalOptions that are missing keep the value in SentryOptions for filter lists * changelog
1 parent e5e95de commit afe9d2c

File tree

6 files changed

+70
-3
lines changed

6 files changed

+70
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
### Fixes
1515

1616
- `SentryOptions.setTracePropagationTargets` is no longer marked internal ([#4170](https://github.com/getsentry/sentry-java/pull/4170))
17+
- Fix `ignoredErrors`, `ignoredTransactions` and `ignoredCheckIns` being unset by external options like `sentry.properties` or ENV vars ([#4207](https://github.com/getsentry/sentry-java/pull/4207))
18+
- Whenever parsing of external options was enabled (`enableExternalConfiguration`), which is the default for many integrations, the values set on `SentryOptions` passed to `Sentry.init` would be lost
19+
- Even if the value was not set in any external configuration it would still be set to an empty list
1720

1821
### Behavioural Changes
1922

sentry/api/sentry.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4029,6 +4029,7 @@ public abstract interface class io/sentry/config/PropertiesProvider {
40294029
public fun getBooleanProperty (Ljava/lang/String;)Ljava/lang/Boolean;
40304030
public fun getDoubleProperty (Ljava/lang/String;)Ljava/lang/Double;
40314031
public fun getList (Ljava/lang/String;)Ljava/util/List;
4032+
public fun getListOrNull (Ljava/lang/String;)Ljava/util/List;
40324033
public fun getLongProperty (Ljava/lang/String;)Ljava/lang/Long;
40334034
public abstract fun getMap (Ljava/lang/String;)Ljava/util/Map;
40344035
public abstract fun getProperty (Ljava/lang/String;)Ljava/lang/String;

sentry/src/main/java/io/sentry/ExternalOptions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public final class ExternalOptions {
128128
}
129129
options.setIdleTimeout(propertiesProvider.getLongProperty("idle-timeout"));
130130

131-
options.setIgnoredErrors(propertiesProvider.getList("ignored-errors"));
131+
options.setIgnoredErrors(propertiesProvider.getListOrNull("ignored-errors"));
132132

133133
options.setEnabled(propertiesProvider.getBooleanProperty("enabled"));
134134

@@ -138,8 +138,8 @@ public final class ExternalOptions {
138138
options.setSendModules(propertiesProvider.getBooleanProperty("send-modules"));
139139
options.setSendDefaultPii(propertiesProvider.getBooleanProperty("send-default-pii"));
140140

141-
options.setIgnoredCheckIns(propertiesProvider.getList("ignored-checkins"));
142-
options.setIgnoredTransactions(propertiesProvider.getList("ignored-transactions"));
141+
options.setIgnoredCheckIns(propertiesProvider.getListOrNull("ignored-checkins"));
142+
options.setIgnoredTransactions(propertiesProvider.getListOrNull("ignored-transactions"));
143143

144144
options.setEnableBackpressureHandling(
145145
propertiesProvider.getBooleanProperty("enable-backpressure-handling"));

sentry/src/main/java/io/sentry/config/PropertiesProvider.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ default List<String> getList(final @NotNull String property) {
3838
return value != null ? Arrays.asList(value.split(",")) : Collections.emptyList();
3939
}
4040

41+
/**
42+
* Resolves a list of values for a property given by it's name.
43+
*
44+
* @param property - the property name
45+
* @return the list or null if not found
46+
*/
47+
@Nullable
48+
default List<String> getListOrNull(final @NotNull String property) {
49+
final String value = getProperty(property);
50+
return value != null ? Arrays.asList(value.split(",")) : null;
51+
}
52+
4153
/**
4254
* Resolves property given by it's name.
4355
*

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ class ExternalOptionsTest {
218218
}
219219
}
220220

221+
@Test
222+
fun `creates options with null ignored errors if missing`() {
223+
val logger = mock<ILogger>()
224+
withPropertiesFile("Another .*", logger) { options ->
225+
assertNull(options.ignoredErrors)
226+
}
227+
}
228+
221229
@Test
222230
fun `creates options with single bundle ID using external properties`() {
223231
withPropertiesFile("bundle-ids=12ea7a02-46ac-44c0-a5bb-6d1fd9586411") { options ->
@@ -270,13 +278,29 @@ class ExternalOptionsTest {
270278
}
271279
}
272280

281+
@Test
282+
fun `creates options with null ignoredCheckIns if missing`() {
283+
val logger = mock<ILogger>()
284+
withPropertiesFile("Another .*", logger) { options ->
285+
assertNull(options.ignoredCheckIns)
286+
}
287+
}
288+
273289
@Test
274290
fun `creates options with ignoredTransactions`() {
275291
withPropertiesFile("ignored-transactions=transactionName1,transactionName2") { options ->
276292
assertTrue(options.ignoredTransactions!!.containsAll(listOf("transactionName1", "transactionName2")))
277293
}
278294
}
279295

296+
@Test
297+
fun `creates options with null ignoredTransactions if missing`() {
298+
val logger = mock<ILogger>()
299+
withPropertiesFile("Another .*", logger) { options ->
300+
assertNull(options.ignoredTransactions)
301+
}
302+
}
303+
280304
@Test
281305
fun `creates options with enableBackpressureHandling set to false`() {
282306
withPropertiesFile("enable-backpressure-handling=false") { options ->

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,4 +668,31 @@ class SentryOptionsTest {
668668
fun `when options is initialized, InitPriority is set to MEDIUM by default`() {
669669
assertEquals(SentryOptions().initPriority, InitPriority.MEDIUM)
670670
}
671+
672+
@Test
673+
fun `merging options when ignoredErrors is not set preserves the previous value`() {
674+
val externalOptions = ExternalOptions()
675+
val options = SentryOptions()
676+
options.setIgnoredErrors(listOf("error1", "error2"))
677+
options.merge(externalOptions)
678+
assertEquals(listOf(FilterString("error1"), FilterString("error2")), options.ignoredErrors)
679+
}
680+
681+
@Test
682+
fun `merging options when ignoredTransactions is not set preserves the previous value`() {
683+
val externalOptions = ExternalOptions()
684+
val options = SentryOptions()
685+
options.setIgnoredTransactions(listOf("transaction1", "transaction2"))
686+
options.merge(externalOptions)
687+
assertEquals(listOf(FilterString("transaction1"), FilterString("transaction2")), options.ignoredTransactions)
688+
}
689+
690+
@Test
691+
fun `merging options when ignoredCheckIns is not set preserves the previous value`() {
692+
val externalOptions = ExternalOptions()
693+
val options = SentryOptions()
694+
options.setIgnoredCheckIns(listOf("checkin1", "checkin2"))
695+
options.merge(externalOptions)
696+
assertEquals(listOf(FilterString("checkin1"), FilterString("checkin2")), options.ignoredCheckIns)
697+
}
671698
}

0 commit comments

Comments
 (0)