From b9bad2a4c20d9c7434c35bcae8a2ac071930054e Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 11 Nov 2026 16:32:16 +0100 Subject: [PATCH 1/3] feat(tracing): [Ignore HTTP Status 4] Ignore incoming 404s by default Stop sending incoming server transactions that finish with HTTP 404 unless users replace or clear the ignored status configuration. Document the opt-out and cover native Spring and OpenTelemetry paths across supported Spring Boot generations. Fixes #4736 --- CHANGELOG.md | 38 ++++++++++++++ .../boot4/integrationtest/IntegrationTest.kt | 1 - .../integrationtest/PersonIntegrationTest.kt | 2 +- .../PersonIntegrationTest.kt | 12 +++++ .../PersonIntegrationTest.kt | 10 ++++ .../PersonWebfluxIntegrationTest.kt | 2 +- .../WebfluxIntegrationTest.kt | 1 - .../boot4/SentryAutoConfigurationTest.kt | 9 ++++ .../integrationtest/IntegrationTest.kt | 1 - .../integrationtest/PersonIntegrationTest.kt | 2 +- .../PersonIntegrationTest.kt | 12 +++++ .../PersonIntegrationTest.kt | 10 ++++ .../PersonWebfluxIntegrationTest.kt | 2 +- .../WebfluxIntegrationTest.kt | 1 - .../jakarta/SentryAutoConfigurationTest.kt | 9 ++++ sentry-spring-boot/README.md | 24 +++++++-- .../boot/integrationtest/IntegrationTest.kt | 1 - .../integrationtest/PersonIntegrationTest.kt | 2 +- .../PersonIntegrationTest.kt | 12 +++++ .../PersonIntegrationTest.kt | 10 ++++ .../PersonWebfluxIntegrationTest.kt | 2 +- .../WebfluxIntegrationTest.kt | 1 - .../boot/SentryAutoConfigurationTest.kt | 9 ++++ .../main/java/io/sentry/SentryOptions.java | 23 +++++---- .../test/java/io/sentry/SentryClientTest.kt | 50 +++++++++---------- .../test/java/io/sentry/SentryOptionsTest.kt | 39 ++++++++++++--- 26 files changed, 226 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3be6c06d934..18370342f96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,44 @@ `logsEnabled` argument. Pass `false` to keep Sentry Logs disabled. - Disable tracing for HTTP `OPTIONS` requests by default. Set `traceOptionsRequests` to `true` to preserve the previous behavior ([#6254](https://github.com/getsentry/sentry-java/pull/6254)) +- Incoming HTTP server transactions that finish with status 404 are no longer sent to Sentry by + default. This includes matched endpoints that intentionally return 404. Outgoing HTTP requests + that receive a 404 are unaffected. + + Restore the previous behavior and trace every incoming HTTP status with an empty configuration: + + Java: + + ```java + import java.util.Collections; + + options.setTraceIgnoreStatusCodes(Collections.emptyList()); + ``` + + `sentry.properties`: + + ```properties + trace-ignore-status-codes= + ``` + + Spring Boot `application.properties`: + + ```properties + sentry.trace-ignore-status-codes= + ``` + + Spring Boot `application.yml`: + + ```yaml + sentry: + trace-ignore-status-codes: [] + ``` + + The final response status is only known after sampling and request handling. The transaction may + already have propagated a sampled trace to downstream services, which can still report their + segments. Local child spans are discarded with the ignored transaction. Continuous profile + chunks are reported independently. External OTLP export does not pass through `SentryClient` and + is not filtered by this option. - Remove the Apache HttpClient transport and stop publishing `sentry-apache-http-client-5` ([#6214](https://github.com/getsentry/sentry-java/pull/6214)) - Remove the deprecated `Instrumenter` enum, option, span context property, and `startChild` overloads ([#6252](https://github.com/getsentry/sentry-java/pull/6252)) - Remove deprecated OpenTelemetry integration classes and the legacy `SentrySpanStorage` ([#6243](https://github.com/getsentry/sentry-java/pull/6243)) diff --git a/sentry-spring-boot-4/src/integrationTest/kotlin/io/sentry/spring/boot4/integrationtest/IntegrationTest.kt b/sentry-spring-boot-4/src/integrationTest/kotlin/io/sentry/spring/boot4/integrationtest/IntegrationTest.kt index ed7c9965864..f61ad6c3826 100644 --- a/sentry-spring-boot-4/src/integrationTest/kotlin/io/sentry/spring/boot4/integrationtest/IntegrationTest.kt +++ b/sentry-spring-boot-4/src/integrationTest/kotlin/io/sentry/spring/boot4/integrationtest/IntegrationTest.kt @@ -29,7 +29,6 @@ import org.springframework.test.context.junit4.SpringRunner properties = [ "sentry.traces-sample-rate=1.0", - "sentry.trace-ignore-status-codes=404", "sentry.clients.ok-http-enabled=true", "sentry.enable-cache-tracing=true", "sentry.enable-queue-tracing=true", diff --git a/sentry-spring-boot-4/src/integrationTest/kotlin/io/sentry/spring/boot4/integrationtest/PersonIntegrationTest.kt b/sentry-spring-boot-4/src/integrationTest/kotlin/io/sentry/spring/boot4/integrationtest/PersonIntegrationTest.kt index ee18a3b7233..f6045b89b7e 100644 --- a/sentry-spring-boot-4/src/integrationTest/kotlin/io/sentry/spring/boot4/integrationtest/PersonIntegrationTest.kt +++ b/sentry-spring-boot-4/src/integrationTest/kotlin/io/sentry/spring/boot4/integrationtest/PersonIntegrationTest.kt @@ -103,7 +103,7 @@ class PersonIntegrationTest : IntegrationTest() { } @Test - fun `configured not found response does not send a transaction`() { + fun `default not found response does not send a transaction`() { val path = "/missing-ignored-status" val response = restTemplate.getForEntity(path, String::class.java) diff --git a/sentry-spring-boot-4/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot4/otelagentintegrationtest/PersonIntegrationTest.kt b/sentry-spring-boot-4/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot4/otelagentintegrationtest/PersonIntegrationTest.kt index 09d7aecda14..7d81b9389ff 100644 --- a/sentry-spring-boot-4/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot4/otelagentintegrationtest/PersonIntegrationTest.kt +++ b/sentry-spring-boot-4/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot4/otelagentintegrationtest/PersonIntegrationTest.kt @@ -20,6 +20,18 @@ import org.springframework.http.HttpHeaders class PersonIntegrationTest : IntegrationTest() { + @Test + fun `default not found response does not send a transaction`() { + val path = "/missing-default-ignored-status" + + val response = restTemplate.getForEntity(path, String::class.java) + + assertThat(response.statusCode.value()).isEqualTo(404) + server.assertNoEnvelope(millis = 1_000) { + it.transaction()?.request?.url?.endsWith(path) == true + } + } + @Test fun `failed request reports errors, spans with their flags, and logs`() { val response = restTemplate.getForEntity("/person/11", String::class.java) diff --git a/sentry-spring-boot-4/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot4/otelnoagentintegrationtest/PersonIntegrationTest.kt b/sentry-spring-boot-4/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot4/otelnoagentintegrationtest/PersonIntegrationTest.kt index 6e0359c459b..4274747cee7 100644 --- a/sentry-spring-boot-4/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot4/otelnoagentintegrationtest/PersonIntegrationTest.kt +++ b/sentry-spring-boot-4/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot4/otelnoagentintegrationtest/PersonIntegrationTest.kt @@ -21,6 +21,16 @@ import org.springframework.http.HttpHeaders class PersonIntegrationTest : IntegrationTest() { + @Test + fun `default not found response does not send a transaction`() { + val path = "/missing-default-ignored-status" + + val response = restTemplate.getForEntity(path, String::class.java) + + assertThat(response.statusCode.value()).isEqualTo(404) + server.assertNoEnvelope { it.transaction()?.request?.url?.endsWith(path) == true } + } + @Test fun `failed request reports errors, nested spans with their flags, and logs`() { val response = restTemplate.getForEntity("/person/11", String::class.java) diff --git a/sentry-spring-boot-4/src/integrationTestWebflux/kotlin/io/sentry/spring/boot4/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt b/sentry-spring-boot-4/src/integrationTestWebflux/kotlin/io/sentry/spring/boot4/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt index 7af3dbcfdf4..8a283f7d046 100644 --- a/sentry-spring-boot-4/src/integrationTestWebflux/kotlin/io/sentry/spring/boot4/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt +++ b/sentry-spring-boot-4/src/integrationTestWebflux/kotlin/io/sentry/spring/boot4/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt @@ -67,7 +67,7 @@ class PersonWebfluxIntegrationTest : WebfluxIntegrationTest() { } @Test - fun `configured not found response does not send a transaction`() { + fun `default not found response does not send a transaction`() { val path = "/missing-ignored-status" val response = restTemplate.getForEntity(path, String::class.java) diff --git a/sentry-spring-boot-4/src/integrationTestWebflux/kotlin/io/sentry/spring/boot4/webfluxintegrationtest/WebfluxIntegrationTest.kt b/sentry-spring-boot-4/src/integrationTestWebflux/kotlin/io/sentry/spring/boot4/webfluxintegrationtest/WebfluxIntegrationTest.kt index d510cc6625a..360dcbb1617 100644 --- a/sentry-spring-boot-4/src/integrationTestWebflux/kotlin/io/sentry/spring/boot4/webfluxintegrationtest/WebfluxIntegrationTest.kt +++ b/sentry-spring-boot-4/src/integrationTestWebflux/kotlin/io/sentry/spring/boot4/webfluxintegrationtest/WebfluxIntegrationTest.kt @@ -26,7 +26,6 @@ import org.springframework.test.context.junit4.SpringRunner properties = [ "sentry.traces-sample-rate=1.0", - "sentry.trace-ignore-status-codes=404", "sentry.enable-cache-tracing=true", "sentry.logs.enabled=true", "sentry.reactive.thread-local-accessor-enabled=true", diff --git a/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt b/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt index 41f60072cb8..989135c8cbb 100644 --- a/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt @@ -341,6 +341,15 @@ class SentryAutoConfigurationTest { } } + @Test + fun `ignored server HTTP status codes default to 404`() { + contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run { + val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes + assertThat(ranges).hasSize(1) + assertThat(ranges!!.single().isInRange(404)).isTrue() + } + } + @Test fun `empty ignored server HTTP status codes disable the configuration`() { contextRunner diff --git a/sentry-spring-boot-jakarta/src/integrationTest/kotlin/io/sentry/spring/boot/jakarta/integrationtest/IntegrationTest.kt b/sentry-spring-boot-jakarta/src/integrationTest/kotlin/io/sentry/spring/boot/jakarta/integrationtest/IntegrationTest.kt index 5b247e5a792..d539470ae93 100644 --- a/sentry-spring-boot-jakarta/src/integrationTest/kotlin/io/sentry/spring/boot/jakarta/integrationtest/IntegrationTest.kt +++ b/sentry-spring-boot-jakarta/src/integrationTest/kotlin/io/sentry/spring/boot/jakarta/integrationtest/IntegrationTest.kt @@ -29,7 +29,6 @@ import org.springframework.test.context.junit4.SpringRunner properties = [ "sentry.traces-sample-rate=1.0", - "sentry.trace-ignore-status-codes=404", "sentry.clients.ok-http-enabled=true", "sentry.enable-cache-tracing=true", "sentry.enable-queue-tracing=true", diff --git a/sentry-spring-boot-jakarta/src/integrationTest/kotlin/io/sentry/spring/boot/jakarta/integrationtest/PersonIntegrationTest.kt b/sentry-spring-boot-jakarta/src/integrationTest/kotlin/io/sentry/spring/boot/jakarta/integrationtest/PersonIntegrationTest.kt index 919034786d6..40638a251c5 100644 --- a/sentry-spring-boot-jakarta/src/integrationTest/kotlin/io/sentry/spring/boot/jakarta/integrationtest/PersonIntegrationTest.kt +++ b/sentry-spring-boot-jakarta/src/integrationTest/kotlin/io/sentry/spring/boot/jakarta/integrationtest/PersonIntegrationTest.kt @@ -103,7 +103,7 @@ class PersonIntegrationTest : IntegrationTest() { } @Test - fun `configured not found response does not send a transaction`() { + fun `default not found response does not send a transaction`() { val path = "/missing-ignored-status" val response = restTemplate.getForEntity(path, String::class.java) diff --git a/sentry-spring-boot-jakarta/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/jakarta/otelagentintegrationtest/PersonIntegrationTest.kt b/sentry-spring-boot-jakarta/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/jakarta/otelagentintegrationtest/PersonIntegrationTest.kt index 62b2012163a..f9526f4e6ff 100644 --- a/sentry-spring-boot-jakarta/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/jakarta/otelagentintegrationtest/PersonIntegrationTest.kt +++ b/sentry-spring-boot-jakarta/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/jakarta/otelagentintegrationtest/PersonIntegrationTest.kt @@ -20,6 +20,18 @@ import org.springframework.http.HttpHeaders class PersonIntegrationTest : IntegrationTest() { + @Test + fun `default not found response does not send a transaction`() { + val path = "/missing-default-ignored-status" + + val response = restTemplate.getForEntity(path, String::class.java) + + assertThat(response.statusCode.value()).isEqualTo(404) + server.assertNoEnvelope(millis = 1_000) { + it.transaction()?.request?.url?.endsWith(path) == true + } + } + @Test fun `failed request reports errors, spans with their flags, and logs`() { val response = restTemplate.getForEntity("/person/11", String::class.java) diff --git a/sentry-spring-boot-jakarta/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot/jakarta/otelnoagentintegrationtest/PersonIntegrationTest.kt b/sentry-spring-boot-jakarta/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot/jakarta/otelnoagentintegrationtest/PersonIntegrationTest.kt index e2ca6eb7b56..07e068ff7a6 100644 --- a/sentry-spring-boot-jakarta/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot/jakarta/otelnoagentintegrationtest/PersonIntegrationTest.kt +++ b/sentry-spring-boot-jakarta/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot/jakarta/otelnoagentintegrationtest/PersonIntegrationTest.kt @@ -21,6 +21,16 @@ import org.springframework.http.HttpHeaders class PersonIntegrationTest : IntegrationTest() { + @Test + fun `default not found response does not send a transaction`() { + val path = "/missing-default-ignored-status" + + val response = restTemplate.getForEntity(path, String::class.java) + + assertThat(response.statusCode.value()).isEqualTo(404) + server.assertNoEnvelope { it.transaction()?.request?.url?.endsWith(path) == true } + } + @Test fun `failed request reports errors, nested spans with their flags, and logs`() { val response = restTemplate.getForEntity("/person/11", String::class.java) diff --git a/sentry-spring-boot-jakarta/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/jakarta/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt b/sentry-spring-boot-jakarta/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/jakarta/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt index f437453e3b7..dcc87e293af 100644 --- a/sentry-spring-boot-jakarta/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/jakarta/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt +++ b/sentry-spring-boot-jakarta/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/jakarta/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt @@ -67,7 +67,7 @@ class PersonWebfluxIntegrationTest : WebfluxIntegrationTest() { } @Test - fun `configured not found response does not send a transaction`() { + fun `default not found response does not send a transaction`() { val path = "/missing-ignored-status" val response = restTemplate.getForEntity(path, String::class.java) diff --git a/sentry-spring-boot-jakarta/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/jakarta/webfluxintegrationtest/WebfluxIntegrationTest.kt b/sentry-spring-boot-jakarta/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/jakarta/webfluxintegrationtest/WebfluxIntegrationTest.kt index d11d38ff0b7..4d314719e35 100644 --- a/sentry-spring-boot-jakarta/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/jakarta/webfluxintegrationtest/WebfluxIntegrationTest.kt +++ b/sentry-spring-boot-jakarta/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/jakarta/webfluxintegrationtest/WebfluxIntegrationTest.kt @@ -26,7 +26,6 @@ import org.springframework.test.context.junit4.SpringRunner properties = [ "sentry.traces-sample-rate=1.0", - "sentry.trace-ignore-status-codes=404", "sentry.enable-cache-tracing=true", "sentry.logs.enabled=true", "sentry.reactive.thread-local-accessor-enabled=true", diff --git a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt index 7dd5f7d92d9..0888249f935 100644 --- a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt @@ -349,6 +349,15 @@ class SentryAutoConfigurationTest { } } + @Test + fun `ignored server HTTP status codes default to 404`() { + contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run { + val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes + assertThat(ranges).hasSize(1) + assertThat(ranges!!.single().isInRange(404)).isTrue() + } + } + @Test fun `empty ignored server HTTP status codes disable the configuration`() { contextRunner diff --git a/sentry-spring-boot/README.md b/sentry-spring-boot/README.md index 8791331b9b1..4d6f6c9c1a3 100644 --- a/sentry-spring-boot/README.md +++ b/sentry-spring-boot/README.md @@ -7,13 +7,27 @@ For more information check out [Sentry Spring Boot documentation](https://docs.s ## Ignoring server transactions by HTTP status -Set `sentry.trace-ignore-status-codes` to a comma-separated list of individual -status codes and inclusive ranges: +Incoming server transactions that finish with HTTP status 404 are not sent to Sentry by default. +Set `sentry.trace-ignore-status-codes` to replace the default with a +comma-separated list of individual status codes and inclusive ranges: ```properties sentry.trace-ignore-status-codes=404,500-599 ``` -Matching incoming server transactions are not sent to Sentry. The filter reads the root -transaction's HTTP response status; child span statuses do not affect it. The option is disabled -when it is unset or empty. +Use an empty value to trace every incoming HTTP status: + +```properties +sentry.trace-ignore-status-codes= +``` + +For YAML configuration, use an empty list: + +```yaml +sentry: + trace-ignore-status-codes: [] +``` + +The filter reads the root transaction's HTTP response status; child span statuses do not affect it. +Filtering happens after the response status is known, so the request may already have propagated a +sampled trace, and local child spans are discarded with the transaction. diff --git a/sentry-spring-boot/src/integrationTest/kotlin/io/sentry/spring/boot/integrationtest/IntegrationTest.kt b/sentry-spring-boot/src/integrationTest/kotlin/io/sentry/spring/boot/integrationtest/IntegrationTest.kt index 03c4214b917..a83f50a73f3 100644 --- a/sentry-spring-boot/src/integrationTest/kotlin/io/sentry/spring/boot/integrationtest/IntegrationTest.kt +++ b/sentry-spring-boot/src/integrationTest/kotlin/io/sentry/spring/boot/integrationtest/IntegrationTest.kt @@ -29,7 +29,6 @@ import org.springframework.test.context.junit4.SpringRunner properties = [ "sentry.traces-sample-rate=1.0", - "sentry.trace-ignore-status-codes=404", "sentry.clients.ok-http-enabled=true", "sentry.enable-cache-tracing=true", "sentry.enable-queue-tracing=true", diff --git a/sentry-spring-boot/src/integrationTest/kotlin/io/sentry/spring/boot/integrationtest/PersonIntegrationTest.kt b/sentry-spring-boot/src/integrationTest/kotlin/io/sentry/spring/boot/integrationtest/PersonIntegrationTest.kt index fa17b781b01..84009cc9151 100644 --- a/sentry-spring-boot/src/integrationTest/kotlin/io/sentry/spring/boot/integrationtest/PersonIntegrationTest.kt +++ b/sentry-spring-boot/src/integrationTest/kotlin/io/sentry/spring/boot/integrationtest/PersonIntegrationTest.kt @@ -103,7 +103,7 @@ class PersonIntegrationTest : IntegrationTest() { } @Test - fun `configured not found response does not send a transaction`() { + fun `default not found response does not send a transaction`() { val path = "/missing-ignored-status" val response = restTemplate.getForEntity(path, String::class.java) diff --git a/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/PersonIntegrationTest.kt b/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/PersonIntegrationTest.kt index 53a52f77412..e979aa0e04e 100644 --- a/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/PersonIntegrationTest.kt +++ b/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/PersonIntegrationTest.kt @@ -20,6 +20,18 @@ import org.springframework.http.HttpHeaders class PersonIntegrationTest : IntegrationTest() { + @Test + fun `default not found response does not send a transaction`() { + val path = "/missing-default-ignored-status" + + val response = restTemplate.getForEntity(path, String::class.java) + + assertThat(response.statusCode.value()).isEqualTo(404) + server.assertNoEnvelope(millis = 1_000) { + it.transaction()?.request?.url?.endsWith(path) == true + } + } + @Test fun `failed request reports errors, spans with their flags, and logs`() { val response = restTemplate.getForEntity("/person/11", String::class.java) diff --git a/sentry-spring-boot/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot/otelnoagentintegrationtest/PersonIntegrationTest.kt b/sentry-spring-boot/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot/otelnoagentintegrationtest/PersonIntegrationTest.kt index 6e9b1c1038b..c9a5ffb72bc 100644 --- a/sentry-spring-boot/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot/otelnoagentintegrationtest/PersonIntegrationTest.kt +++ b/sentry-spring-boot/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot/otelnoagentintegrationtest/PersonIntegrationTest.kt @@ -21,6 +21,16 @@ import org.springframework.http.HttpHeaders class PersonIntegrationTest : IntegrationTest() { + @Test + fun `default not found response does not send a transaction`() { + val path = "/missing-default-ignored-status" + + val response = restTemplate.getForEntity(path, String::class.java) + + assertThat(response.statusCode.value()).isEqualTo(404) + server.assertNoEnvelope { it.transaction()?.request?.url?.endsWith(path) == true } + } + @Test fun `failed request reports errors, nested spans with their flags, and logs`() { val response = restTemplate.getForEntity("/person/11", String::class.java) diff --git a/sentry-spring-boot/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt b/sentry-spring-boot/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt index 35c00694d6f..57584cba90a 100644 --- a/sentry-spring-boot/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt +++ b/sentry-spring-boot/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt @@ -67,7 +67,7 @@ class PersonWebfluxIntegrationTest : WebfluxIntegrationTest() { } @Test - fun `configured not found response does not send a transaction`() { + fun `default not found response does not send a transaction`() { val path = "/missing-ignored-status" val response = restTemplate.getForEntity(path, String::class.java) diff --git a/sentry-spring-boot/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/webfluxintegrationtest/WebfluxIntegrationTest.kt b/sentry-spring-boot/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/webfluxintegrationtest/WebfluxIntegrationTest.kt index a626555e26a..f222e37b4ef 100644 --- a/sentry-spring-boot/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/webfluxintegrationtest/WebfluxIntegrationTest.kt +++ b/sentry-spring-boot/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/webfluxintegrationtest/WebfluxIntegrationTest.kt @@ -26,7 +26,6 @@ import org.springframework.test.context.junit4.SpringRunner properties = [ "sentry.traces-sample-rate=1.0", - "sentry.trace-ignore-status-codes=404", "sentry.logs.enabled=true", "sentry.profile-session-sample-rate=1.0", "sentry.profile-lifecycle=TRACE", diff --git a/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt b/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt index cbb06d39e01..f492486cab3 100644 --- a/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt @@ -347,6 +347,15 @@ class SentryAutoConfigurationTest { } } + @Test + fun `ignored server HTTP status codes default to 404`() { + contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run { + val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes + assertThat(ranges).hasSize(1) + assertThat(ranges!!.single().isInRange(404)).isTrue() + } + } + @Test fun `empty ignored server HTTP status codes disable the configuration`() { contextRunner diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java index efbc0de9ae0..d936582bcdf 100644 --- a/sentry/src/main/java/io/sentry/SentryOptions.java +++ b/sentry/src/main/java/io/sentry/SentryOptions.java @@ -598,7 +598,8 @@ public class SentryOptions implements RateLimiterConfig { */ private @Nullable List ignoredTransactions = null; - private @Nullable List traceIgnoreStatusCodes = null; + private @Nullable List traceIgnoreStatusCodes = + new ArrayList<>(Collections.singletonList(new HttpStatusCodeRange(404))); @ApiStatus.Experimental private @NotNull IBackpressureMonitor backpressureMonitor = NoOpBackpressureMonitor.getInstance(); @@ -3151,9 +3152,10 @@ public void setIgnoredTransactions(final @Nullable List ignoredTransacti /** * Returns the HTTP status codes and inclusive ranges for which incoming server transactions are - * not sent to Sentry. An empty list disables this filter. + * not sent to Sentry. Defaults to a single range containing 404. An empty list disables this + * filter. * - * @return the configured HTTP status code ranges, or {@code null} if unset + * @return the configured HTTP status code ranges, or {@code null} if explicitly set to null */ public @Nullable List getTraceIgnoreStatusCodes() { return traceIgnoreStatusCodes; @@ -3163,16 +3165,18 @@ public void setIgnoredTransactions(final @Nullable List ignoredTransacti * Sets the HTTP status codes and inclusive ranges for which incoming server transactions are not * sent to Sentry. For example, configure {@code new HttpStatusCodeRange(404)} for one status or * {@code new HttpStatusCodeRange(500, 599)} for an inclusive range. External configuration - * accepts comma-separated codes and ranges such as {@code 404,410,500-599}. An empty list - * disables this filter. + * accepts comma-separated codes and ranges such as {@code 404,410,500-599}. An empty list or + * {@code null} disables this filter. * - * @param traceIgnoreStatusCodes the HTTP status code ranges, or {@code null} to leave the option - * unset + * @param traceIgnoreStatusCodes the HTTP status code ranges, or {@code null} to + * disable the filter */ public void setTraceIgnoreStatusCodes( final @Nullable List traceIgnoreStatusCodes) { this.traceIgnoreStatusCodes = - traceIgnoreStatusCodes == null ? null : new ArrayList<>(traceIgnoreStatusCodes); + traceIgnoreStatusCodes == null + ? null + : new ArrayList<>(traceIgnoreStatusCodes); } /** Returns the current {@link SentryDateProvider} that is used to retrieve the current date. */ @@ -3852,7 +3856,8 @@ public void merge(final @NotNull ExternalOptions options) { setIgnoredTransactions(ignoredTransactions); } if (options.getTraceIgnoreStatusCodes() != null) { - setTraceIgnoreStatusCodes(options.getTraceIgnoreStatusCodes()); + setTraceIgnoreStatusCodes( + options.getTraceIgnoreStatusCodes()); } if (options.getIgnoredErrors() != null) { final List ignoredExceptions = new ArrayList<>(options.getIgnoredErrors()); diff --git a/sentry/src/test/java/io/sentry/SentryClientTest.kt b/sentry/src/test/java/io/sentry/SentryClientTest.kt index fe55ef2d15b..30c34449284 100644 --- a/sentry/src/test/java/io/sentry/SentryClientTest.kt +++ b/sentry/src/test/java/io/sentry/SentryClientTest.kt @@ -1385,10 +1385,7 @@ class SentryClientTest { } @Test - fun `server transaction with ignored HTTP status is dropped before callbacks`() { - fixture.sentryOptions.setTraceIgnoreStatusCodes( - listOf(HttpStatusCodeRange(404)) - ) + fun `server transaction with default ignored HTTP status is dropped before callbacks`() { val processor = mock() val beforeSend = mock() val replayController = mock() @@ -1425,18 +1422,29 @@ class SentryClientTest { } @Test - fun `server transaction with ignored HTTP status range accepts OTel long value`() { + fun `default HTTP status filter retains server 200`() { + fixture + .getSut() + .captureTransaction(createServerTransaction(200), fixture.sentryTracer.traceContext()) + + verify(fixture.transport).send(any(), anyOrNull()) + } + + @Test + fun `custom HTTP status range replaces default and accepts OTel long value`() { fixture.sentryOptions.setTraceIgnoreStatusCodes( listOf(HttpStatusCodeRange(500, 599)) ) + val sut = fixture.getSut() - val eventId = - fixture - .getSut() - .captureTransaction(createServerTransaction(503L), fixture.sentryTracer.traceContext()) + val ignoredEventId = + sut.captureTransaction(createServerTransaction(503L), fixture.sentryTracer.traceContext()) + val retainedEventId = + sut.captureTransaction(createServerTransaction(404), fixture.sentryTracer.traceContext()) - assertThat(eventId).isEqualTo(SentryId.EMPTY_ID) - verify(fixture.transport, never()).send(any(), anyOrNull()) + assertThat(ignoredEventId).isEqualTo(SentryId.EMPTY_ID) + assertThat(retainedEventId).isNotEqualTo(SentryId.EMPTY_ID) + verify(fixture.transport).send(any(), anyOrNull()) } @Test @@ -1451,10 +1459,7 @@ class SentryClientTest { } @Test - fun `HTTP status filter only applies to server transactions`() { - fixture.sentryOptions.setTraceIgnoreStatusCodes( - listOf(HttpStatusCodeRange(404)) - ) + fun `default HTTP status filter only applies to server transactions`() { val clientTransaction = createServerTransaction(404) clientTransaction.contexts.trace!!.data[SpanDataConvention.SENTRY_KIND_KEY] = "client" val missingKindTransaction = createServerTransaction(404) @@ -1468,10 +1473,7 @@ class SentryClientTest { } @Test - fun `HTTP status filter ignores missing and invalid root status values`() { - fixture.sentryOptions.setTraceIgnoreStatusCodes( - listOf(HttpStatusCodeRange(404)) - ) + fun `default HTTP status filter ignores missing and invalid root status values`() { val invalidStatusValues = listOf("404", 404.0, 404.5f, 99, 600, Long.MAX_VALUE) val sut = fixture.getSut() @@ -1489,10 +1491,7 @@ class SentryClientTest { } @Test - fun `HTTP status filter does not read child span attributes`() { - fixture.sentryOptions.setTraceIgnoreStatusCodes( - listOf(HttpStatusCodeRange(404)) - ) + fun `default HTTP status filter does not read child span attributes`() { val tracer = SentryTracer( TransactionContext("child-status-transaction", "op", TracesSamplingDecision(true)), @@ -1511,10 +1510,7 @@ class SentryClientTest { } @Test - fun `profiling trace deletion failure for ignored transaction is logged`() { - fixture.sentryOptions.setTraceIgnoreStatusCodes( - listOf(HttpStatusCodeRange(404)) - ) + fun `profiling trace deletion failure for default ignored transaction is logged`() { val traceFile = mock() whenever(traceFile.delete()).thenReturn(false) whenever(traceFile.path).thenReturn("undeletable.trace") diff --git a/sentry/src/test/java/io/sentry/SentryOptionsTest.kt b/sentry/src/test/java/io/sentry/SentryOptionsTest.kt index b1fe1242642..6efbfc703d6 100644 --- a/sentry/src/test/java/io/sentry/SentryOptionsTest.kt +++ b/sentry/src/test/java/io/sentry/SentryOptionsTest.kt @@ -1088,29 +1088,46 @@ class SentryOptionsTest { } @Test - fun `ignored server HTTP status codes for tracing are unset by default`() { - assertNull(SentryOptions().traceIgnoreStatusCodes) + fun `ignored server HTTP status codes for tracing default to 404`() { + val ranges = SentryOptions().traceIgnoreStatusCodes + + assertThat(ranges).hasSize(1) + assertThat(ranges!!.single().isInRange(404)).isTrue() + } + + @Test + fun `default ignored server HTTP status code lists are independent`() { + val first = SentryOptions().traceIgnoreStatusCodes!! + val second = SentryOptions().traceIgnoreStatusCodes!! + + first.clear() + + assertThat(second).hasSize(1) + assertThat(second.single().isInRange(404)).isTrue() } @Test - fun `ignored server HTTP status code setter preserves empty and custom ranges`() { + fun `ignored server HTTP status code setter preserves null, empty and custom ranges`() { val options = SentryOptions() + options.traceIgnoreStatusCodes = null + assertThat(options.traceIgnoreStatusCodes).isNull() + options.traceIgnoreStatusCodes = emptyList() assertThat(options.traceIgnoreStatusCodes).isEmpty() - options.traceIgnoreStatusCodes = listOf(HttpStatusCodeRange(404), HttpStatusCodeRange(500, 599)) + options.traceIgnoreStatusCodes = + listOf(HttpStatusCodeRange(404), HttpStatusCodeRange(500, 599)) assertThat(options.traceIgnoreStatusCodes).hasSize(2) assertThat(options.traceIgnoreStatusCodes!![0].isInRange(404)).isTrue() assertThat(options.traceIgnoreStatusCodes!![1].isInRange(599)).isTrue() } @Test - fun `merging empty ignored server HTTP status codes replaces the previous value`() { + fun `merging empty ignored server HTTP status codes clears the default`() { val externalOptions = ExternalOptions() externalOptions.traceIgnoreStatusCodes = emptyList() val options = SentryOptions() - options.traceIgnoreStatusCodes = listOf(HttpStatusCodeRange(404)) options.merge(externalOptions) @@ -1128,6 +1145,16 @@ class SentryOptionsTest { assertThat(options.traceIgnoreStatusCodes!![0].isInRange(410)).isTrue() } + @Test + fun `merging options when ignored server HTTP status codes are not set preserves default`() { + val options = SentryOptions() + + options.merge(ExternalOptions()) + + assertThat(options.traceIgnoreStatusCodes).hasSize(1) + assertThat(options.traceIgnoreStatusCodes!!.single().isInRange(404)).isTrue() + } + @Test fun `merging options when ignoredErrors is not set preserves the previous value`() { val externalOptions = ExternalOptions() From becc6d04de058c5a759395672cb52b24ce83ff44 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 11 Nov 2026 16:34:18 +0100 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 2 +- sentry/src/main/java/io/sentry/SentryOptions.java | 11 ++++------- sentry/src/test/java/io/sentry/SentryClientTest.kt | 4 +--- sentry/src/test/java/io/sentry/SentryOptionsTest.kt | 3 +-- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18370342f96..e602ff2d604 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,7 +89,7 @@ already have propagated a sampled trace to downstream services, which can still report their segments. Local child spans are discarded with the ignored transaction. Continuous profile chunks are reported independently. External OTLP export does not pass through `SentryClient` and - is not filtered by this option. + is not filtered by this option ([#6567](https://github.com/getsentry/sentry-java/pull/6567)) - Remove the Apache HttpClient transport and stop publishing `sentry-apache-http-client-5` ([#6214](https://github.com/getsentry/sentry-java/pull/6214)) - Remove the deprecated `Instrumenter` enum, option, span context property, and `startChild` overloads ([#6252](https://github.com/getsentry/sentry-java/pull/6252)) - Remove deprecated OpenTelemetry integration classes and the legacy `SentrySpanStorage` ([#6243](https://github.com/getsentry/sentry-java/pull/6243)) diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java index d936582bcdf..3fec7e91762 100644 --- a/sentry/src/main/java/io/sentry/SentryOptions.java +++ b/sentry/src/main/java/io/sentry/SentryOptions.java @@ -3168,15 +3168,13 @@ public void setIgnoredTransactions(final @Nullable List ignoredTransacti * accepts comma-separated codes and ranges such as {@code 404,410,500-599}. An empty list or * {@code null} disables this filter. * - * @param traceIgnoreStatusCodes the HTTP status code ranges, or {@code null} to - * disable the filter + * @param traceIgnoreStatusCodes the HTTP status code ranges, or {@code null} to disable the + * filter */ public void setTraceIgnoreStatusCodes( final @Nullable List traceIgnoreStatusCodes) { this.traceIgnoreStatusCodes = - traceIgnoreStatusCodes == null - ? null - : new ArrayList<>(traceIgnoreStatusCodes); + traceIgnoreStatusCodes == null ? null : new ArrayList<>(traceIgnoreStatusCodes); } /** Returns the current {@link SentryDateProvider} that is used to retrieve the current date. */ @@ -3856,8 +3854,7 @@ public void merge(final @NotNull ExternalOptions options) { setIgnoredTransactions(ignoredTransactions); } if (options.getTraceIgnoreStatusCodes() != null) { - setTraceIgnoreStatusCodes( - options.getTraceIgnoreStatusCodes()); + setTraceIgnoreStatusCodes(options.getTraceIgnoreStatusCodes()); } if (options.getIgnoredErrors() != null) { final List ignoredExceptions = new ArrayList<>(options.getIgnoredErrors()); diff --git a/sentry/src/test/java/io/sentry/SentryClientTest.kt b/sentry/src/test/java/io/sentry/SentryClientTest.kt index 30c34449284..f88130250c1 100644 --- a/sentry/src/test/java/io/sentry/SentryClientTest.kt +++ b/sentry/src/test/java/io/sentry/SentryClientTest.kt @@ -1432,9 +1432,7 @@ class SentryClientTest { @Test fun `custom HTTP status range replaces default and accepts OTel long value`() { - fixture.sentryOptions.setTraceIgnoreStatusCodes( - listOf(HttpStatusCodeRange(500, 599)) - ) + fixture.sentryOptions.setTraceIgnoreStatusCodes(listOf(HttpStatusCodeRange(500, 599))) val sut = fixture.getSut() val ignoredEventId = diff --git a/sentry/src/test/java/io/sentry/SentryOptionsTest.kt b/sentry/src/test/java/io/sentry/SentryOptionsTest.kt index 6efbfc703d6..6a80635bd40 100644 --- a/sentry/src/test/java/io/sentry/SentryOptionsTest.kt +++ b/sentry/src/test/java/io/sentry/SentryOptionsTest.kt @@ -1116,8 +1116,7 @@ class SentryOptionsTest { options.traceIgnoreStatusCodes = emptyList() assertThat(options.traceIgnoreStatusCodes).isEmpty() - options.traceIgnoreStatusCodes = - listOf(HttpStatusCodeRange(404), HttpStatusCodeRange(500, 599)) + options.traceIgnoreStatusCodes = listOf(HttpStatusCodeRange(404), HttpStatusCodeRange(500, 599)) assertThat(options.traceIgnoreStatusCodes).hasSize(2) assertThat(options.traceIgnoreStatusCodes!![0].isInRange(404)).isTrue() assertThat(options.traceIgnoreStatusCodes!![1].isInRange(599)).isTrue() From cf2f6fc302238f32691549f2137cb5d93a9275a5 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Tue, 17 Nov 2026 11:07:00 +0100 Subject: [PATCH 3/3] feat(tracing): Align ignored status defaults with spec Default traceIgnoreStatusCodes to 301-303, 305-399, and 401-404 instead of only 404. Update documentation and boundary coverage so excluded gaps remain captured. Refs #4736 Co-Authored-By: Claude --- CHANGELOG.md | 6 ++--- .../boot4/SentryAutoConfigurationTest.kt | 13 +++++++--- .../jakarta/SentryAutoConfigurationTest.kt | 13 +++++++--- sentry-spring-boot/README.md | 4 +-- .../boot/SentryAutoConfigurationTest.kt | 13 +++++++--- .../main/java/io/sentry/SentryOptions.java | 9 +++++-- .../test/java/io/sentry/SentryClientTest.kt | 25 +++++++++++++++---- .../test/java/io/sentry/SentryOptionsTest.kt | 23 +++++++++++------ 8 files changed, 74 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e602ff2d604..8ed609d1f23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,9 +52,9 @@ `logsEnabled` argument. Pass `false` to keep Sentry Logs disabled. - Disable tracing for HTTP `OPTIONS` requests by default. Set `traceOptionsRequests` to `true` to preserve the previous behavior ([#6254](https://github.com/getsentry/sentry-java/pull/6254)) -- Incoming HTTP server transactions that finish with status 404 are no longer sent to Sentry by - default. This includes matched endpoints that intentionally return 404. Outgoing HTTP requests - that receive a 404 are unaffected. +- Incoming HTTP server transactions that finish with status 301-303, 305-399, or 401-404 are no + longer sent to Sentry by default. This includes matched endpoints that intentionally return one + of these statuses. Outgoing HTTP requests with matching statuses are unaffected. Restore the previous behavior and trace every incoming HTTP status with an empty configuration: diff --git a/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt b/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt index eb88d735113..f2d02ce4825 100644 --- a/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt @@ -343,11 +343,16 @@ class SentryAutoConfigurationTest { } @Test - fun `ignored server HTTP status codes default to 404`() { + fun `ignored server HTTP status codes use the spec defaults`() { contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run { - val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes - assertThat(ranges).hasSize(1) - assertThat(ranges!!.single().isInRange(404)).isTrue() + val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes!! + assertThat(ranges).hasSize(3) + listOf(301, 303, 305, 399, 401, 404).forEach { statusCode -> + assertThat(ranges.any { it.isInRange(statusCode) }).isTrue() + } + listOf(300, 304, 400, 405).forEach { statusCode -> + assertThat(ranges.any { it.isInRange(statusCode) }).isFalse() + } } } diff --git a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt index d5305fcab45..a7630082a74 100644 --- a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt @@ -351,11 +351,16 @@ class SentryAutoConfigurationTest { } @Test - fun `ignored server HTTP status codes default to 404`() { + fun `ignored server HTTP status codes use the spec defaults`() { contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run { - val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes - assertThat(ranges).hasSize(1) - assertThat(ranges!!.single().isInRange(404)).isTrue() + val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes!! + assertThat(ranges).hasSize(3) + listOf(301, 303, 305, 399, 401, 404).forEach { statusCode -> + assertThat(ranges.any { it.isInRange(statusCode) }).isTrue() + } + listOf(300, 304, 400, 405).forEach { statusCode -> + assertThat(ranges.any { it.isInRange(statusCode) }).isFalse() + } } } diff --git a/sentry-spring-boot/README.md b/sentry-spring-boot/README.md index 4d6f6c9c1a3..b5be441e901 100644 --- a/sentry-spring-boot/README.md +++ b/sentry-spring-boot/README.md @@ -7,8 +7,8 @@ For more information check out [Sentry Spring Boot documentation](https://docs.s ## Ignoring server transactions by HTTP status -Incoming server transactions that finish with HTTP status 404 are not sent to Sentry by default. -Set `sentry.trace-ignore-status-codes` to replace the default with a +Incoming server transactions that finish with HTTP status 301-303, 305-399, or 401-404 are not +sent to Sentry by default. Set `sentry.trace-ignore-status-codes` to replace the default with a comma-separated list of individual status codes and inclusive ranges: ```properties diff --git a/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt b/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt index 3076bb532ce..2cdec61d620 100644 --- a/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt @@ -349,11 +349,16 @@ class SentryAutoConfigurationTest { } @Test - fun `ignored server HTTP status codes default to 404`() { + fun `ignored server HTTP status codes use the spec defaults`() { contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run { - val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes - assertThat(ranges).hasSize(1) - assertThat(ranges!!.single().isInRange(404)).isTrue() + val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes!! + assertThat(ranges).hasSize(3) + listOf(301, 303, 305, 399, 401, 404).forEach { statusCode -> + assertThat(ranges.any { it.isInRange(statusCode) }).isTrue() + } + listOf(300, 304, 400, 405).forEach { statusCode -> + assertThat(ranges.any { it.isInRange(statusCode) }).isFalse() + } } } diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java index 3fec7e91762..b32769c6823 100644 --- a/sentry/src/main/java/io/sentry/SentryOptions.java +++ b/sentry/src/main/java/io/sentry/SentryOptions.java @@ -40,6 +40,7 @@ import io.sentry.util.thread.NoOpThreadChecker; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -599,7 +600,11 @@ public class SentryOptions implements RateLimiterConfig { private @Nullable List ignoredTransactions = null; private @Nullable List traceIgnoreStatusCodes = - new ArrayList<>(Collections.singletonList(new HttpStatusCodeRange(404))); + new ArrayList<>( + Arrays.asList( + new HttpStatusCodeRange(301, 303), + new HttpStatusCodeRange(305, 399), + new HttpStatusCodeRange(401, 404))); @ApiStatus.Experimental private @NotNull IBackpressureMonitor backpressureMonitor = NoOpBackpressureMonitor.getInstance(); @@ -3152,7 +3157,7 @@ public void setIgnoredTransactions(final @Nullable List ignoredTransacti /** * Returns the HTTP status codes and inclusive ranges for which incoming server transactions are - * not sent to Sentry. Defaults to a single range containing 404. An empty list disables this + * not sent to Sentry. Defaults to 301-303, 305-399, and 401-404. An empty list disables this * filter. * * @return the configured HTTP status code ranges, or {@code null} if explicitly set to null diff --git a/sentry/src/test/java/io/sentry/SentryClientTest.kt b/sentry/src/test/java/io/sentry/SentryClientTest.kt index f88130250c1..b60ce2f97d9 100644 --- a/sentry/src/test/java/io/sentry/SentryClientTest.kt +++ b/sentry/src/test/java/io/sentry/SentryClientTest.kt @@ -1422,12 +1422,27 @@ class SentryClientTest { } @Test - fun `default HTTP status filter retains server 200`() { - fixture - .getSut() - .captureTransaction(createServerTransaction(200), fixture.sentryTracer.traceContext()) + fun `default HTTP status filter drops the spec ranges`() { + val sut = fixture.getSut() - verify(fixture.transport).send(any(), anyOrNull()) + listOf(301, 303, 305, 399, 401, 404).forEach { + val eventId = + sut.captureTransaction(createServerTransaction(it), fixture.sentryTracer.traceContext()) + assertThat(eventId).isEqualTo(SentryId.EMPTY_ID) + } + + verify(fixture.transport, never()).send(any(), anyOrNull()) + } + + @Test + fun `default HTTP status filter retains statuses outside the spec ranges`() { + val sut = fixture.getSut() + + listOf(200, 300, 304, 400, 405).forEach { + sut.captureTransaction(createServerTransaction(it), fixture.sentryTracer.traceContext()) + } + + verify(fixture.transport, times(5)).send(any(), anyOrNull()) } @Test diff --git a/sentry/src/test/java/io/sentry/SentryOptionsTest.kt b/sentry/src/test/java/io/sentry/SentryOptionsTest.kt index 6a80635bd40..7da0b5ced72 100644 --- a/sentry/src/test/java/io/sentry/SentryOptionsTest.kt +++ b/sentry/src/test/java/io/sentry/SentryOptionsTest.kt @@ -1088,11 +1088,16 @@ class SentryOptionsTest { } @Test - fun `ignored server HTTP status codes for tracing default to 404`() { - val ranges = SentryOptions().traceIgnoreStatusCodes + fun `ignored server HTTP status codes for tracing use the spec defaults`() { + val ranges = SentryOptions().traceIgnoreStatusCodes!! - assertThat(ranges).hasSize(1) - assertThat(ranges!!.single().isInRange(404)).isTrue() + assertThat(ranges).hasSize(3) + listOf(301, 303, 305, 399, 401, 404).forEach { + assertThat(ranges.any { range -> range.isInRange(it) }).isTrue() + } + listOf(300, 304, 400, 405).forEach { + assertThat(ranges.any { range -> range.isInRange(it) }).isFalse() + } } @Test @@ -1102,8 +1107,9 @@ class SentryOptionsTest { first.clear() - assertThat(second).hasSize(1) - assertThat(second.single().isInRange(404)).isTrue() + assertThat(second).hasSize(3) + assertThat(second.any { it.isInRange(301) }).isTrue() + assertThat(second.any { it.isInRange(404) }).isTrue() } @Test @@ -1150,8 +1156,9 @@ class SentryOptionsTest { options.merge(ExternalOptions()) - assertThat(options.traceIgnoreStatusCodes).hasSize(1) - assertThat(options.traceIgnoreStatusCodes!!.single().isInRange(404)).isTrue() + assertThat(options.traceIgnoreStatusCodes).hasSize(3) + assertThat(options.traceIgnoreStatusCodes!!.any { it.isInRange(301) }).isTrue() + assertThat(options.traceIgnoreStatusCodes!!.any { it.isInRange(404) }).isTrue() } @Test