Skip to content

Commit cf2f6fc

Browse files
adinauerclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 0a7d341 commit cf2f6fc

8 files changed

Lines changed: 74 additions & 32 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
`logsEnabled` argument. Pass `false` to keep Sentry Logs disabled.
5353
- Disable tracing for HTTP `OPTIONS` requests by default. Set `traceOptionsRequests` to `true` to
5454
preserve the previous behavior ([#6254](https://github.com/getsentry/sentry-java/pull/6254))
55-
- Incoming HTTP server transactions that finish with status 404 are no longer sent to Sentry by
56-
default. This includes matched endpoints that intentionally return 404. Outgoing HTTP requests
57-
that receive a 404 are unaffected.
55+
- Incoming HTTP server transactions that finish with status 301-303, 305-399, or 401-404 are no
56+
longer sent to Sentry by default. This includes matched endpoints that intentionally return one
57+
of these statuses. Outgoing HTTP requests with matching statuses are unaffected.
5858

5959
Restore the previous behavior and trace every incoming HTTP status with an empty configuration:
6060

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,16 @@ class SentryAutoConfigurationTest {
343343
}
344344

345345
@Test
346-
fun `ignored server HTTP status codes default to 404`() {
346+
fun `ignored server HTTP status codes use the spec defaults`() {
347347
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run {
348-
val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes
349-
assertThat(ranges).hasSize(1)
350-
assertThat(ranges!!.single().isInRange(404)).isTrue()
348+
val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes!!
349+
assertThat(ranges).hasSize(3)
350+
listOf(301, 303, 305, 399, 401, 404).forEach { statusCode ->
351+
assertThat(ranges.any { it.isInRange(statusCode) }).isTrue()
352+
}
353+
listOf(300, 304, 400, 405).forEach { statusCode ->
354+
assertThat(ranges.any { it.isInRange(statusCode) }).isFalse()
355+
}
351356
}
352357
}
353358

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,16 @@ class SentryAutoConfigurationTest {
351351
}
352352

353353
@Test
354-
fun `ignored server HTTP status codes default to 404`() {
354+
fun `ignored server HTTP status codes use the spec defaults`() {
355355
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run {
356-
val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes
357-
assertThat(ranges).hasSize(1)
358-
assertThat(ranges!!.single().isInRange(404)).isTrue()
356+
val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes!!
357+
assertThat(ranges).hasSize(3)
358+
listOf(301, 303, 305, 399, 401, 404).forEach { statusCode ->
359+
assertThat(ranges.any { it.isInRange(statusCode) }).isTrue()
360+
}
361+
listOf(300, 304, 400, 405).forEach { statusCode ->
362+
assertThat(ranges.any { it.isInRange(statusCode) }).isFalse()
363+
}
359364
}
360365
}
361366

‎sentry-spring-boot/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ For more information check out [Sentry Spring Boot documentation](https://docs.s
77

88
## Ignoring server transactions by HTTP status
99

10-
Incoming server transactions that finish with HTTP status 404 are not sent to Sentry by default.
11-
Set `sentry.trace-ignore-status-codes` to replace the default with a
10+
Incoming server transactions that finish with HTTP status 301-303, 305-399, or 401-404 are not
11+
sent to Sentry by default. Set `sentry.trace-ignore-status-codes` to replace the default with a
1212
comma-separated list of individual status codes and inclusive ranges:
1313

1414
```properties

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,16 @@ class SentryAutoConfigurationTest {
349349
}
350350

351351
@Test
352-
fun `ignored server HTTP status codes default to 404`() {
352+
fun `ignored server HTTP status codes use the spec defaults`() {
353353
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run {
354-
val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes
355-
assertThat(ranges).hasSize(1)
356-
assertThat(ranges!!.single().isInRange(404)).isTrue()
354+
val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes!!
355+
assertThat(ranges).hasSize(3)
356+
listOf(301, 303, 305, 399, 401, 404).forEach { statusCode ->
357+
assertThat(ranges.any { it.isInRange(statusCode) }).isTrue()
358+
}
359+
listOf(300, 304, 400, 405).forEach { statusCode ->
360+
assertThat(ranges.any { it.isInRange(statusCode) }).isFalse()
361+
}
357362
}
358363
}
359364

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import io.sentry.util.thread.NoOpThreadChecker;
4141
import java.io.File;
4242
import java.util.ArrayList;
43+
import java.util.Arrays;
4344
import java.util.Collections;
4445
import java.util.HashMap;
4546
import java.util.HashSet;
@@ -599,7 +600,11 @@ public class SentryOptions implements RateLimiterConfig {
599600
private @Nullable List<FilterString> ignoredTransactions = null;
600601

601602
private @Nullable List<HttpStatusCodeRange> traceIgnoreStatusCodes =
602-
new ArrayList<>(Collections.singletonList(new HttpStatusCodeRange(404)));
603+
new ArrayList<>(
604+
Arrays.asList(
605+
new HttpStatusCodeRange(301, 303),
606+
new HttpStatusCodeRange(305, 399),
607+
new HttpStatusCodeRange(401, 404)));
603608

604609
@ApiStatus.Experimental
605610
private @NotNull IBackpressureMonitor backpressureMonitor = NoOpBackpressureMonitor.getInstance();
@@ -3152,7 +3157,7 @@ public void setIgnoredTransactions(final @Nullable List<String> ignoredTransacti
31523157

31533158
/**
31543159
* Returns the HTTP status codes and inclusive ranges for which incoming server transactions are
3155-
* not sent to Sentry. Defaults to a single range containing 404. An empty list disables this
3160+
* not sent to Sentry. Defaults to 301-303, 305-399, and 401-404. An empty list disables this
31563161
* filter.
31573162
*
31583163
* @return the configured HTTP status code ranges, or {@code null} if explicitly set to null

‎sentry/src/test/java/io/sentry/SentryClientTest.kt‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,12 +1422,27 @@ class SentryClientTest {
14221422
}
14231423

14241424
@Test
1425-
fun `default HTTP status filter retains server 200`() {
1426-
fixture
1427-
.getSut()
1428-
.captureTransaction(createServerTransaction(200), fixture.sentryTracer.traceContext())
1425+
fun `default HTTP status filter drops the spec ranges`() {
1426+
val sut = fixture.getSut()
14291427

1430-
verify(fixture.transport).send(any(), anyOrNull())
1428+
listOf(301, 303, 305, 399, 401, 404).forEach {
1429+
val eventId =
1430+
sut.captureTransaction(createServerTransaction(it), fixture.sentryTracer.traceContext())
1431+
assertThat(eventId).isEqualTo(SentryId.EMPTY_ID)
1432+
}
1433+
1434+
verify(fixture.transport, never()).send(any(), anyOrNull())
1435+
}
1436+
1437+
@Test
1438+
fun `default HTTP status filter retains statuses outside the spec ranges`() {
1439+
val sut = fixture.getSut()
1440+
1441+
listOf(200, 300, 304, 400, 405).forEach {
1442+
sut.captureTransaction(createServerTransaction(it), fixture.sentryTracer.traceContext())
1443+
}
1444+
1445+
verify(fixture.transport, times(5)).send(any(), anyOrNull())
14311446
}
14321447

14331448
@Test

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,11 +1088,16 @@ class SentryOptionsTest {
10881088
}
10891089

10901090
@Test
1091-
fun `ignored server HTTP status codes for tracing default to 404`() {
1092-
val ranges = SentryOptions().traceIgnoreStatusCodes
1091+
fun `ignored server HTTP status codes for tracing use the spec defaults`() {
1092+
val ranges = SentryOptions().traceIgnoreStatusCodes!!
10931093

1094-
assertThat(ranges).hasSize(1)
1095-
assertThat(ranges!!.single().isInRange(404)).isTrue()
1094+
assertThat(ranges).hasSize(3)
1095+
listOf(301, 303, 305, 399, 401, 404).forEach {
1096+
assertThat(ranges.any { range -> range.isInRange(it) }).isTrue()
1097+
}
1098+
listOf(300, 304, 400, 405).forEach {
1099+
assertThat(ranges.any { range -> range.isInRange(it) }).isFalse()
1100+
}
10961101
}
10971102

10981103
@Test
@@ -1102,8 +1107,9 @@ class SentryOptionsTest {
11021107

11031108
first.clear()
11041109

1105-
assertThat(second).hasSize(1)
1106-
assertThat(second.single().isInRange(404)).isTrue()
1110+
assertThat(second).hasSize(3)
1111+
assertThat(second.any { it.isInRange(301) }).isTrue()
1112+
assertThat(second.any { it.isInRange(404) }).isTrue()
11071113
}
11081114

11091115
@Test
@@ -1150,8 +1156,9 @@ class SentryOptionsTest {
11501156

11511157
options.merge(ExternalOptions())
11521158

1153-
assertThat(options.traceIgnoreStatusCodes).hasSize(1)
1154-
assertThat(options.traceIgnoreStatusCodes!!.single().isInRange(404)).isTrue()
1159+
assertThat(options.traceIgnoreStatusCodes).hasSize(3)
1160+
assertThat(options.traceIgnoreStatusCodes!!.any { it.isInRange(301) }).isTrue()
1161+
assertThat(options.traceIgnoreStatusCodes!!.any { it.isInRange(404) }).isTrue()
11551162
}
11561163

11571164
@Test

0 commit comments

Comments
 (0)