diff --git a/CHANGELOG.md b/CHANGELOG.md index 3be6c06d934..8ed609d1f23 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 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: + + 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 ([#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-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 d79ae7116d0..3117be7f36e 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 e21346f07af..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 @@ -342,6 +342,20 @@ class SentryAutoConfigurationTest { } } + @Test + 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(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() + } + } + } + @Test fun `YAML list binds integer ignored server HTTP status codes`() { dsnEnabledRunner 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 ee4cd87213b..38ac40a13e4 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 df95c4fe635..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 @@ -350,6 +350,20 @@ class SentryAutoConfigurationTest { } } + @Test + 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(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() + } + } + } + @Test fun `YAML list binds integer ignored server HTTP status codes`() { dsnEnabledRunner diff --git a/sentry-spring-boot/README.md b/sentry-spring-boot/README.md index 8791331b9b1..b5be441e901 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 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 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 ffbd58483d8..a4700865c0c 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 1af23f3b814..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 @@ -348,6 +348,20 @@ class SentryAutoConfigurationTest { } } + @Test + 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(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() + } + } + } + @Test fun `YAML list binds integer ignored server HTTP status codes`() { dsnEnabledRunner diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java index efbc0de9ae0..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; @@ -598,7 +599,12 @@ public class SentryOptions implements RateLimiterConfig { */ private @Nullable List ignoredTransactions = null; - private @Nullable List traceIgnoreStatusCodes = null; + private @Nullable List traceIgnoreStatusCodes = + new ArrayList<>( + Arrays.asList( + new HttpStatusCodeRange(301, 303), + new HttpStatusCodeRange(305, 399), + new HttpStatusCodeRange(401, 404))); @ApiStatus.Experimental private @NotNull IBackpressureMonitor backpressureMonitor = NoOpBackpressureMonitor.getInstance(); @@ -3151,9 +3157,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 301-303, 305-399, and 401-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,11 +3170,11 @@ 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) { diff --git a/sentry/src/test/java/io/sentry/SentryClientTest.kt b/sentry/src/test/java/io/sentry/SentryClientTest.kt index fe55ef2d15b..b60ce2f97d9 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,20 +1422,44 @@ class SentryClientTest { } @Test - fun `server transaction with ignored HTTP status range accepts OTel long value`() { - fixture.sentryOptions.setTraceIgnoreStatusCodes( - listOf(HttpStatusCodeRange(500, 599)) - ) + fun `default HTTP status filter drops the spec ranges`() { + val sut = fixture.getSut() - val eventId = - fixture - .getSut() - .captureTransaction(createServerTransaction(503L), fixture.sentryTracer.traceContext()) + listOf(301, 303, 305, 399, 401, 404).forEach { + val eventId = + sut.captureTransaction(createServerTransaction(it), fixture.sentryTracer.traceContext()) + assertThat(eventId).isEqualTo(SentryId.EMPTY_ID) + } - 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 + fun `custom HTTP status range replaces default and accepts OTel long value`() { + fixture.sentryOptions.setTraceIgnoreStatusCodes(listOf(HttpStatusCodeRange(500, 599))) + val sut = fixture.getSut() + + val ignoredEventId = + sut.captureTransaction(createServerTransaction(503L), fixture.sentryTracer.traceContext()) + val retainedEventId = + sut.captureTransaction(createServerTransaction(404), fixture.sentryTracer.traceContext()) + + assertThat(ignoredEventId).isEqualTo(SentryId.EMPTY_ID) + assertThat(retainedEventId).isNotEqualTo(SentryId.EMPTY_ID) + verify(fixture.transport).send(any(), anyOrNull()) + } + @Test fun `HTTP status filter is disabled for an empty configuration`() { fixture.sentryOptions.setTraceIgnoreStatusCodes(emptyList()) @@ -1451,10 +1472,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 +1486,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 +1504,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 +1523,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..7da0b5ced72 100644 --- a/sentry/src/test/java/io/sentry/SentryOptionsTest.kt +++ b/sentry/src/test/java/io/sentry/SentryOptionsTest.kt @@ -1088,14 +1088,37 @@ 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 use the spec defaults`() { + val ranges = SentryOptions().traceIgnoreStatusCodes!! + + 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 + fun `default ignored server HTTP status code lists are independent`() { + val first = SentryOptions().traceIgnoreStatusCodes!! + val second = SentryOptions().traceIgnoreStatusCodes!! + + first.clear() + + assertThat(second).hasSize(3) + assertThat(second.any { it.isInRange(301) }).isTrue() + assertThat(second.any { it.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() @@ -1106,11 +1129,10 @@ class SentryOptionsTest { } @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 +1150,17 @@ 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(3) + assertThat(options.traceIgnoreStatusCodes!!.any { it.isInRange(301) }).isTrue() + assertThat(options.traceIgnoreStatusCodes!!.any { it.isInRange(404) }).isTrue() + } + @Test fun `merging options when ignoredErrors is not set preserves the previous value`() { val externalOptions = ExternalOptions()