Skip to content

Commit a018c68

Browse files
committed
feat(tracing): Filter configured incoming HTTP statuses
Drop completed incoming server HTTP transactions when their root response status matches a configured range. Preserve lifecycle finalization while skipping processors, callbacks, envelope creation, and replay registration for filtered transactions. Record transaction, span, and profile losses, clean up temporary profile traces, and cover Spring Boot servlet and WebFlux integrations. Fixes #4735
1 parent b80bf59 commit a018c68

17 files changed

Lines changed: 400 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,39 @@
6767

6868
### Features
6969

70+
- Drop incoming server transactions whose root HTTP response status matches `traceIgnoreStatusCodes`. Configure individual statuses such as `404`, inclusive ranges such as `400-499` or `500-599`, or combine them.
71+
72+
Java:
73+
74+
```java
75+
import io.sentry.HttpStatusCodeRange;
76+
import java.util.Arrays;
77+
78+
options.setTraceIgnoreStatusCodes(
79+
Arrays.asList(new HttpStatusCodeRange(404), new HttpStatusCodeRange(500, 599)));
80+
```
81+
82+
`sentry.properties`:
83+
84+
```properties
85+
trace-ignore-status-codes=404,500-599
86+
```
87+
88+
Spring Boot `application.properties`:
89+
90+
```properties
91+
sentry.trace-ignore-status-codes=404,500-599
92+
```
93+
94+
Spring Boot `application.yml`:
95+
96+
```yaml
97+
sentry:
98+
trace-ignore-status-codes:
99+
- "404"
100+
- "500-599"
101+
```
102+
70103
- Monitor every Spring `@Scheduled` method with Sentry Crons by setting `sentry.monitor-scheduled-tasks=true`, without adding `@SentryCheckIn` to each method. Sentry creates each monitor from the method's `@Scheduled` schedule. Exclude methods with `sentry.exclude-scheduled-tasks` ([#6275](https://github.com/getsentry/sentry-java/pull/6275), [#6276](https://github.com/getsentry/sentry-java/pull/6276), [#6277](https://github.com/getsentry/sentry-java/pull/6277))
71104
- Quartz `SentryJobListener` can send a monitor config derived from the trigger with check-ins, so Sentry creates or updates the monitor from code. Set the `sentry-upsert-monitor-config` job or trigger data key to `"true"` to send the schedule ([#6216](https://github.com/getsentry/sentry-java/pull/6216))
72105
- Send a monitor config derived from Spring `@Scheduled` with `@SentryCheckIn` check-ins, so Sentry creates or updates the monitor from code. Set `@SentryCheckIn(upsertMonitorConfig = true)` to send the schedule ([#6215](https://github.com/getsentry/sentry-java/pull/6215))

‎sentry-spring-boot-4/src/integrationTest/kotlin/io/sentry/spring/boot4/integrationtest/IntegrationTest.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.springframework.test.context.junit4.SpringRunner
2929
properties =
3030
[
3131
"sentry.traces-sample-rate=1.0",
32+
"sentry.trace-ignore-status-codes=404",
3233
"sentry.clients.ok-http-enabled=true",
3334
"sentry.enable-cache-tracing=true",
3435
"sentry.enable-queue-tracing=true",

‎sentry-spring-boot-4/src/integrationTest/kotlin/io/sentry/spring/boot4/integrationtest/PersonIntegrationTest.kt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ class PersonIntegrationTest : IntegrationTest() {
102102
.isTrue()
103103
}
104104

105+
@Test
106+
fun `configured not found response does not send a transaction`() {
107+
val path = "/missing-ignored-status"
108+
109+
val response = restTemplate.getForEntity(path, String::class.java)
110+
111+
assertThat(response.statusCode.value()).isEqualTo(404)
112+
Sentry.flush(5000)
113+
server.assertNoEnvelope { it.transaction()?.request?.url?.endsWith(path) == true }
114+
}
115+
105116
@Test
106117
fun `creating a person starts a profile linked to the transaction`() {
107118
val response =

‎sentry-spring-boot-4/src/integrationTestWebflux/kotlin/io/sentry/spring/boot4/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ class PersonWebfluxIntegrationTest : WebfluxIntegrationTest() {
6666
.isEqualTo(200)
6767
}
6868

69+
@Test
70+
fun `configured not found response does not send a transaction`() {
71+
val path = "/missing-ignored-status"
72+
73+
val response = restTemplate.getForEntity(path, String::class.java)
74+
75+
assertThat(response.statusCode.value()).isEqualTo(404)
76+
Sentry.flush(5000)
77+
server.assertNoEnvelope { it.transaction()?.request?.url?.endsWith(path) == true }
78+
}
79+
6980
@Test
7081
fun `creating a person starts a profile linked to the transaction`() {
7182
val response =

‎sentry-spring-boot-4/src/integrationTestWebflux/kotlin/io/sentry/spring/boot4/webfluxintegrationtest/WebfluxIntegrationTest.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.springframework.test.context.junit4.SpringRunner
2626
properties =
2727
[
2828
"sentry.traces-sample-rate=1.0",
29+
"sentry.trace-ignore-status-codes=404",
2930
"sentry.enable-cache-tracing=true",
3031
"sentry.logs.enabled=true",
3132
"sentry.reactive.thread-local-accessor-enabled=true",

‎sentry-spring-boot-jakarta/src/integrationTest/kotlin/io/sentry/spring/boot/jakarta/integrationtest/IntegrationTest.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.springframework.test.context.junit4.SpringRunner
2929
properties =
3030
[
3131
"sentry.traces-sample-rate=1.0",
32+
"sentry.trace-ignore-status-codes=404",
3233
"sentry.clients.ok-http-enabled=true",
3334
"sentry.enable-cache-tracing=true",
3435
"sentry.enable-queue-tracing=true",

‎sentry-spring-boot-jakarta/src/integrationTest/kotlin/io/sentry/spring/boot/jakarta/integrationtest/PersonIntegrationTest.kt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ class PersonIntegrationTest : IntegrationTest() {
102102
.isTrue()
103103
}
104104

105+
@Test
106+
fun `configured not found response does not send a transaction`() {
107+
val path = "/missing-ignored-status"
108+
109+
val response = restTemplate.getForEntity(path, String::class.java)
110+
111+
assertThat(response.statusCode.value()).isEqualTo(404)
112+
Sentry.flush(5000)
113+
server.assertNoEnvelope { it.transaction()?.request?.url?.endsWith(path) == true }
114+
}
115+
105116
@Test
106117
fun `creating a person starts a profile linked to the transaction`() {
107118
val response =

‎sentry-spring-boot-jakarta/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/jakarta/webfluxintegrationtest/PersonWebfluxIntegrationTest.kt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ class PersonWebfluxIntegrationTest : WebfluxIntegrationTest() {
6666
.isEqualTo(200)
6767
}
6868

69+
@Test
70+
fun `configured not found response does not send a transaction`() {
71+
val path = "/missing-ignored-status"
72+
73+
val response = restTemplate.getForEntity(path, String::class.java)
74+
75+
assertThat(response.statusCode.value()).isEqualTo(404)
76+
Sentry.flush(5000)
77+
server.assertNoEnvelope { it.transaction()?.request?.url?.endsWith(path) == true }
78+
}
79+
6980
@Test
7081
fun `creating a person starts a profile linked to the transaction`() {
7182
val response =

‎sentry-spring-boot-jakarta/src/integrationTestWebflux/kotlin/io/sentry/spring/boot/jakarta/webfluxintegrationtest/WebfluxIntegrationTest.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.springframework.test.context.junit4.SpringRunner
2626
properties =
2727
[
2828
"sentry.traces-sample-rate=1.0",
29+
"sentry.trace-ignore-status-codes=404",
2930
"sentry.enable-cache-tracing=true",
3031
"sentry.logs.enabled=true",
3132
"sentry.reactive.thread-local-accessor-enabled=true",

‎sentry-spring-boot/README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,16 @@ This integration is ideal to Spring Boot users. It buids on top of [Sentry's cor
44
and also integrates well with logback or log4j2 if those are used in the application.
55

66
For more information check out [Sentry Spring Boot documentation](https://docs.sentry.io/platforms/java/guides/spring-boot/).
7+
8+
## Ignoring server transactions by HTTP status
9+
10+
Set `sentry.trace-ignore-status-codes` to a comma-separated list of individual
11+
status codes and inclusive ranges:
12+
13+
```properties
14+
sentry.trace-ignore-status-codes=404,500-599
15+
```
16+
17+
Matching incoming server transactions are not sent to Sentry. The filter reads the root
18+
transaction's HTTP response status; child span statuses do not affect it. The option is disabled
19+
when it is unset or empty.

0 commit comments

Comments
 (0)