Skip to content

Commit e7fdb28

Browse files
adinauerclaude
andauthored
feat(core): [Ignore HTTP Status 2] Add traceIgnoreStatusCodes configuration (#6559)
* feat(core): [Ignore HTTP Status 2] Add tracing status configuration Add an unset option for ignored incoming server HTTP status codes and ranges. Parse external configuration without clearing existing values when all entries are invalid, and support Spring Boot binding across all supported versions. This PR only adds configuration surfaces; filtering remains unchanged. Refs #4735 * fix(spring): Bind integer HTTP status codes from YAML Support unquoted numeric entries in Spring Boot YAML lists while preserving status code validation across Boot 2, 3, and 4. Refs #4735 Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
2 parents 737909a + 6e6beba commit e7fdb28

10 files changed

Lines changed: 444 additions & 0 deletions

File tree

‎sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import org.springframework.context.annotation.Bean
8585
import org.springframework.context.annotation.Configuration
8686
import org.springframework.core.Ordered
8787
import org.springframework.core.annotation.Order
88+
import org.springframework.core.env.MapPropertySource
8889
import org.springframework.scheduling.annotation.EnableScheduling
8990
import org.springframework.scheduling.annotation.Scheduled
9091
import org.springframework.scheduling.quartz.SchedulerFactoryBean
@@ -263,6 +264,7 @@ class SentryAutoConfigurationTest {
263264
"sentry.ignored-checkins=slug1,slugB",
264265
"sentry.ignored-errors=Some error,Another .*",
265266
"sentry.ignored-transactions=transactionName1,transactionNameB",
267+
"sentry.trace-ignore-status-codes=404,500-599",
266268
"sentry.enable-backpressure-handling=false",
267269
"sentry.enable-database-transaction-tracing=true",
268270
"sentry.enable-cache-tracing=true",
@@ -316,6 +318,10 @@ class SentryAutoConfigurationTest {
316318
assertThat(options.ignoredCheckIns).containsOnly("slug1", "slugB")
317319
assertThat(options.ignoredErrors).containsOnly("Some error", "Another .*")
318320
assertThat(options.ignoredTransactions).containsOnly("transactionName1", "transactionNameB")
321+
assertThat(options.traceIgnoreStatusCodes).hasSize(2)
322+
assertThat(options.traceIgnoreStatusCodes!![0].isInRange(404)).isTrue()
323+
assertThat(options.traceIgnoreStatusCodes!![1].isInRange(500)).isTrue()
324+
assertThat(options.traceIgnoreStatusCodes!![1].isInRange(599)).isTrue()
319325
assertThat(options.isEnableBackpressureHandling).isEqualTo(false)
320326
assertThat(options.isEnableDatabaseTransactionTracing).isEqualTo(true)
321327
assertThat(options.isEnableCacheTracing).isEqualTo(true)
@@ -336,6 +342,42 @@ class SentryAutoConfigurationTest {
336342
}
337343
}
338344

345+
@Test
346+
fun `YAML list binds integer ignored server HTTP status codes`() {
347+
dsnEnabledRunner
348+
.withInitializer { context ->
349+
// YAML exposes unquoted numbers as Integer values in indexed property sources.
350+
context.environment.propertySources.addFirst(
351+
MapPropertySource(
352+
"yaml",
353+
mapOf<String, Any>(
354+
"sentry.trace-ignore-status-codes[0]" to 404,
355+
"sentry.trace-ignore-status-codes[1]" to "500-599",
356+
),
357+
)
358+
)
359+
}
360+
.run {
361+
val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes
362+
assertThat(ranges).hasSize(2)
363+
assertThat(ranges!![0].isInRange(404)).isTrue()
364+
assertThat(ranges[1].isInRange(500)).isTrue()
365+
assertThat(ranges[1].isInRange(599)).isTrue()
366+
}
367+
}
368+
369+
@Test
370+
fun `empty ignored server HTTP status codes disable the configuration`() {
371+
contextRunner
372+
.withPropertyValues(
373+
"sentry.dsn=http://key@localhost/proj",
374+
"sentry.trace-ignore-status-codes=",
375+
)
376+
.run {
377+
assertThat(it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes).isEmpty()
378+
}
379+
}
380+
339381
@Test
340382
fun `data collection properties are applied to SentryOptions`() {
341383
contextRunner

‎sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import org.springframework.context.annotation.Bean
8888
import org.springframework.context.annotation.Configuration
8989
import org.springframework.core.Ordered
9090
import org.springframework.core.annotation.Order
91+
import org.springframework.core.env.MapPropertySource
9192
import org.springframework.scheduling.annotation.EnableScheduling
9293
import org.springframework.scheduling.annotation.Scheduled
9394
import org.springframework.scheduling.quartz.SchedulerFactoryBean
@@ -266,6 +267,7 @@ class SentryAutoConfigurationTest {
266267
"sentry.ignored-checkins=slug1,slugB",
267268
"sentry.ignored-errors=Some error,Another .*",
268269
"sentry.ignored-transactions=transactionName1,transactionNameB",
270+
"sentry.trace-ignore-status-codes=404,500-599",
269271
"sentry.enable-backpressure-handling=false",
270272
"sentry.enable-database-transaction-tracing=true",
271273
"sentry.enable-spotlight=true",
@@ -321,6 +323,10 @@ class SentryAutoConfigurationTest {
321323
assertThat(options.ignoredCheckIns).containsOnly("slug1", "slugB")
322324
assertThat(options.ignoredErrors).containsOnly("Some error", "Another .*")
323325
assertThat(options.ignoredTransactions).containsOnly("transactionName1", "transactionNameB")
326+
assertThat(options.traceIgnoreStatusCodes).hasSize(2)
327+
assertThat(options.traceIgnoreStatusCodes!![0].isInRange(404)).isTrue()
328+
assertThat(options.traceIgnoreStatusCodes!![1].isInRange(500)).isTrue()
329+
assertThat(options.traceIgnoreStatusCodes!![1].isInRange(599)).isTrue()
324330
assertThat(options.isEnableBackpressureHandling).isEqualTo(false)
325331
assertThat(options.isEnableDatabaseTransactionTracing).isEqualTo(true)
326332
assertThat(options.isForceInit).isEqualTo(true)
@@ -344,6 +350,42 @@ class SentryAutoConfigurationTest {
344350
}
345351
}
346352

353+
@Test
354+
fun `YAML list binds integer ignored server HTTP status codes`() {
355+
dsnEnabledRunner
356+
.withInitializer { context ->
357+
// YAML exposes unquoted numbers as Integer values in indexed property sources.
358+
context.environment.propertySources.addFirst(
359+
MapPropertySource(
360+
"yaml",
361+
mapOf<String, Any>(
362+
"sentry.trace-ignore-status-codes[0]" to 404,
363+
"sentry.trace-ignore-status-codes[1]" to "500-599",
364+
),
365+
)
366+
)
367+
}
368+
.run {
369+
val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes
370+
assertThat(ranges).hasSize(2)
371+
assertThat(ranges!![0].isInRange(404)).isTrue()
372+
assertThat(ranges[1].isInRange(500)).isTrue()
373+
assertThat(ranges[1].isInRange(599)).isTrue()
374+
}
375+
}
376+
377+
@Test
378+
fun `empty ignored server HTTP status codes disable the configuration`() {
379+
contextRunner
380+
.withPropertyValues(
381+
"sentry.dsn=http://key@localhost/proj",
382+
"sentry.trace-ignore-status-codes=",
383+
)
384+
.run {
385+
assertThat(it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes).isEmpty()
386+
}
387+
}
388+
347389
@Test
348390
fun `data collection properties are applied to SentryOptions`() {
349391
contextRunner

‎sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import org.springframework.context.annotation.Bean
8888
import org.springframework.context.annotation.Configuration
8989
import org.springframework.core.Ordered
9090
import org.springframework.core.annotation.Order
91+
import org.springframework.core.env.MapPropertySource
9192
import org.springframework.scheduling.annotation.EnableScheduling
9293
import org.springframework.scheduling.annotation.Scheduled
9394
import org.springframework.scheduling.quartz.SchedulerFactoryBean
@@ -264,6 +265,7 @@ class SentryAutoConfigurationTest {
264265
"sentry.ignored-checkins=slug1,slugB",
265266
"sentry.ignored-errors=Some error,Another .*",
266267
"sentry.ignored-transactions=transactionName1,transactionNameB",
268+
"sentry.trace-ignore-status-codes=404,500-599",
267269
"sentry.enable-backpressure-handling=false",
268270
"sentry.enable-database-transaction-tracing=true",
269271
"sentry.enable-spotlight=true",
@@ -319,6 +321,10 @@ class SentryAutoConfigurationTest {
319321
assertThat(options.ignoredCheckIns).containsOnly("slug1", "slugB")
320322
assertThat(options.ignoredErrors).containsOnly("Some error", "Another .*")
321323
assertThat(options.ignoredTransactions).containsOnly("transactionName1", "transactionNameB")
324+
assertThat(options.traceIgnoreStatusCodes).hasSize(2)
325+
assertThat(options.traceIgnoreStatusCodes!![0].isInRange(404)).isTrue()
326+
assertThat(options.traceIgnoreStatusCodes!![1].isInRange(500)).isTrue()
327+
assertThat(options.traceIgnoreStatusCodes!![1].isInRange(599)).isTrue()
322328
assertThat(options.isEnableBackpressureHandling).isEqualTo(false)
323329
assertThat(options.isEnableDatabaseTransactionTracing).isEqualTo(true)
324330
assertThat(options.isForceInit).isEqualTo(true)
@@ -342,6 +348,42 @@ class SentryAutoConfigurationTest {
342348
}
343349
}
344350

351+
@Test
352+
fun `YAML list binds integer ignored server HTTP status codes`() {
353+
dsnEnabledRunner
354+
.withInitializer { context ->
355+
// YAML exposes unquoted numbers as Integer values in indexed property sources.
356+
context.environment.propertySources.addFirst(
357+
MapPropertySource(
358+
"yaml",
359+
mapOf<String, Any>(
360+
"sentry.trace-ignore-status-codes[0]" to 404,
361+
"sentry.trace-ignore-status-codes[1]" to "500-599",
362+
),
363+
)
364+
)
365+
}
366+
.run {
367+
val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes
368+
assertThat(ranges).hasSize(2)
369+
assertThat(ranges!![0].isInRange(404)).isTrue()
370+
assertThat(ranges[1].isInRange(500)).isTrue()
371+
assertThat(ranges[1].isInRange(599)).isTrue()
372+
}
373+
}
374+
375+
@Test
376+
fun `empty ignored server HTTP status codes disable the configuration`() {
377+
contextRunner
378+
.withPropertyValues(
379+
"sentry.dsn=http://key@localhost/proj",
380+
"sentry.trace-ignore-status-codes=",
381+
)
382+
.run {
383+
assertThat(it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes).isEmpty()
384+
}
385+
}
386+
345387
@Test
346388
fun `data collection properties are applied to SentryOptions`() {
347389
contextRunner

‎sentry/api/sentry.api‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ public final class io/sentry/ExternalOptions {
587587
public fun getShutdownTimeoutMillis ()Ljava/lang/Long;
588588
public fun getSpotlightConnectionUrl ()Ljava/lang/String;
589589
public fun getTags ()Ljava/util/Map;
590+
public fun getTraceIgnoreStatusCodes ()Ljava/util/List;
590591
public fun getTracePropagationTargets ()Ljava/util/List;
591592
public fun getTracesSampleRate ()Ljava/lang/Double;
592593
public fun isCaptureOpenTelemetryEvents ()Ljava/lang/Boolean;
@@ -644,6 +645,7 @@ public final class io/sentry/ExternalOptions {
644645
public fun setSpotlightConnectionUrl (Ljava/lang/String;)V
645646
public fun setStrictTraceContinuation (Ljava/lang/Boolean;)V
646647
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
648+
public fun setTraceIgnoreStatusCodes (Ljava/util/List;)V
647649
public fun setTracesSampleRate (Ljava/lang/Double;)V
648650
}
649651

@@ -710,6 +712,8 @@ public final class io/sentry/HttpStatusCodeRange {
710712
public fun <init> (I)V
711713
public fun <init> (II)V
712714
public fun isInRange (I)Z
715+
public static fun valueOf (Ljava/lang/Integer;)Lio/sentry/HttpStatusCodeRange;
716+
public static fun valueOf (Ljava/lang/String;)Lio/sentry/HttpStatusCodeRange;
713717
}
714718

715719
public abstract interface class io/sentry/IAppStartExtender {
@@ -3616,6 +3620,7 @@ public class io/sentry/SentryOptions : io/sentry/transport/RateLimiterConfig {
36163620
public fun getTags ()Ljava/util/Map;
36173621
public fun getThreadChecker ()Lio/sentry/util/thread/IThreadChecker;
36183622
public fun getTimerExecutorService ()Lio/sentry/ISentryExecutorService;
3623+
public fun getTraceIgnoreStatusCodes ()Ljava/util/List;
36193624
public fun getTracePropagationTargets ()Ljava/util/List;
36203625
public fun getTracesSampleRate ()Ljava/lang/Double;
36213626
public fun getTracesSampler ()Lio/sentry/SentryOptions$TracesSamplerCallback;
@@ -3785,6 +3790,7 @@ public class io/sentry/SentryOptions : io/sentry/transport/RateLimiterConfig {
37853790
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
37863791
public fun setThreadChecker (Lio/sentry/util/thread/IThreadChecker;)V
37873792
public fun setTimerExecutorService (Lio/sentry/ISentryExecutorService;)V
3793+
public fun setTraceIgnoreStatusCodes (Ljava/util/List;)V
37883794
public fun setTraceOptionsRequests (Z)V
37893795
public fun setTracePropagationTargets (Ljava/util/List;)V
37903796
public fun setTraceSampling (Z)V

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public final class ExternalOptions {
5050

5151
private @Nullable List<String> ignoredCheckIns;
5252
private @Nullable List<String> ignoredTransactions;
53+
private @Nullable List<HttpStatusCodeRange> traceIgnoreStatusCodes;
5354

5455
private @Nullable Boolean sendModules;
5556
private @Nullable Boolean sendDefaultPii;
@@ -160,6 +161,7 @@ public final class ExternalOptions {
160161

161162
options.setIgnoredCheckIns(propertiesProvider.getListOrNull("ignored-checkins"));
162163
options.setIgnoredTransactions(propertiesProvider.getListOrNull("ignored-transactions"));
164+
options.setTraceIgnoreStatusCodes(parseTraceIgnoreStatusCodes(propertiesProvider, logger));
163165

164166
options.setEnableBackpressureHandling(
165167
propertiesProvider.getBooleanProperty("enable-backpressure-handling"));
@@ -243,6 +245,30 @@ public final class ExternalOptions {
243245
return options;
244246
}
245247

248+
private static @Nullable List<HttpStatusCodeRange> parseTraceIgnoreStatusCodes(
249+
final @NotNull PropertiesProvider propertiesProvider, final @NotNull ILogger logger) {
250+
final String value = propertiesProvider.getProperty("trace-ignore-status-codes");
251+
if (value == null) {
252+
return null;
253+
}
254+
if (value.trim().isEmpty()) {
255+
return new ArrayList<>();
256+
}
257+
258+
final List<HttpStatusCodeRange> ranges = new ArrayList<>();
259+
for (final String token : value.split(",", -1)) {
260+
try {
261+
ranges.add(HttpStatusCodeRange.valueOf(token));
262+
} catch (IllegalArgumentException e) {
263+
logger.log(
264+
SentryLevel.WARNING,
265+
"Ignoring invalid HTTP status code range in trace-ignore-status-codes: %s",
266+
token);
267+
}
268+
}
269+
return ranges.isEmpty() ? null : ranges;
270+
}
271+
246272
private static @Nullable DataCollection parseDataCollection(
247273
final @NotNull PropertiesProvider propertiesProvider) {
248274
final DataCollection dataCollection = new DataCollection();
@@ -622,6 +648,15 @@ public void setIgnoredTransactions(final @Nullable List<String> ignoredTransacti
622648
return ignoredTransactions;
623649
}
624650

651+
public void setTraceIgnoreStatusCodes(
652+
final @Nullable List<HttpStatusCodeRange> traceIgnoreStatusCodes) {
653+
this.traceIgnoreStatusCodes = traceIgnoreStatusCodes;
654+
}
655+
656+
public @Nullable List<HttpStatusCodeRange> getTraceIgnoreStatusCodes() {
657+
return traceIgnoreStatusCodes;
658+
}
659+
625660
public void setEnableBackpressureHandling(final @Nullable Boolean enableBackpressureHandling) {
626661
this.enableBackpressureHandling = enableBackpressureHandling;
627662
}

0 commit comments

Comments
 (0)