From 16c9ce6c370418af82fbd2a9c834cb9f63d28bc9 Mon Sep 17 00:00:00 2001 From: Giannis Gkiortzis Date: Thu, 30 Oct 2025 13:36:17 +0100 Subject: [PATCH 1/3] feat: ignore 404 status codes --- client.go | 9 ++++++++- client_test.go | 7 ++++++- echo/sentryecho_test.go | 5 +++-- gin/sentrygin_test.go | 5 +++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index 346230223..6d5889318 100644 --- a/client.go +++ b/client.go @@ -247,7 +247,10 @@ type ClientOptions struct { // [][]int{{404}, {500}} // ignore status codes 404 and 500 // [][]int{{404}, {400, 405}, {500, 599}} // ignore 404, range 400-405, and range 500-599 // - // By default, this is empty and all status codes are traced. + // By default, this ignores 404 status codes. + // + // ⚠️ IMPORTANT: to not ignore any status codes, the option should be an empty slice and not nil. The nil option is + // used for defaulting to 404 ignores. TraceIgnoreStatusCodes [][]int } @@ -325,6 +328,10 @@ func NewClient(options ClientOptions) (*Client, error) { options.MaxSpans = defaultMaxSpans } + if options.TraceIgnoreStatusCodes == nil { + options.TraceIgnoreStatusCodes = [][]int{{404}} + } + // SENTRYGODEBUG is a comma-separated list of key=value pairs (similar // to GODEBUG). It is not a supported feature: recognized debug options // may change any time. diff --git a/client_test.go b/client_test.go index de9d43418..9f0eea7ba 100644 --- a/client_test.go +++ b/client_test.go @@ -733,7 +733,12 @@ func TestTraceIgnoreStatusCodes(t *testing.T) { statusCode interface{} expectDrop bool }{ - "No ignored codes": { + "Default behavior: ignoreStatusCodes = nil, should drop 404s": { + statusCode: 404, + ignoreStatusCodes: nil, + expectDrop: true, + }, + "Specify No ignored codes": { statusCode: 404, ignoreStatusCodes: [][]int{}, expectDrop: false, diff --git a/echo/sentryecho_test.go b/echo/sentryecho_test.go index 03a060589..74f17022e 100644 --- a/echo/sentryecho_test.go +++ b/echo/sentryecho_test.go @@ -356,8 +356,9 @@ func TestIntegration(t *testing.T) { transactionsCh := make(chan *sentry.Event, len(tests)) err := sentry.Init(sentry.ClientOptions{ - EnableTracing: true, - TracesSampleRate: 1.0, + EnableTracing: true, + TracesSampleRate: 1.0, + TraceIgnoreStatusCodes: make([][]int, 0), // don't ignore any status codes BeforeSend: func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event { eventsCh <- event return event diff --git a/gin/sentrygin_test.go b/gin/sentrygin_test.go index 01dbdff33..51527872f 100644 --- a/gin/sentrygin_test.go +++ b/gin/sentrygin_test.go @@ -354,8 +354,9 @@ func TestIntegration(t *testing.T) { eventsCh := make(chan *sentry.Event, len(tests)) transactionsCh := make(chan *sentry.Event, len(tests)) err := sentry.Init(sentry.ClientOptions{ - EnableTracing: true, - TracesSampleRate: 1.0, + EnableTracing: true, + TracesSampleRate: 1.0, + TraceIgnoreStatusCodes: make([][]int, 0), // don't ignore any status codes BeforeSend: func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event { eventsCh <- event return event From b97aafe7e47676c9d1e554002385269139771cc6 Mon Sep 17 00:00:00 2001 From: Giannis Gkiortzis Date: Thu, 30 Oct 2025 13:39:35 +0100 Subject: [PATCH 2/3] chore: update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8beaa05f..716eb5ada 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased Changes + +### Breaking Cahnges + +- Behavioral change for the `TraceIgnoreStatusCodes` option. The option now defaults to ignoring 404 status codes. + ## 0.36.2 The Sentry SDK team is happy to announce the immediate availability of Sentry Go SDK v0.36.2. From 7d8c3fd43b6295a053fa7012f3ad15c4dd7c1ff2 Mon Sep 17 00:00:00 2001 From: Giannis Gkiortzis Date: Thu, 30 Oct 2025 14:12:52 +0100 Subject: [PATCH 3/3] chore: wording --- CHANGELOG.md | 2 +- client.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 716eb5ada..c8a7dfd57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased Changes -### Breaking Cahnges +### Breaking Changes - Behavioral change for the `TraceIgnoreStatusCodes` option. The option now defaults to ignoring 404 status codes. diff --git a/client.go b/client.go index 6d5889318..03800f81a 100644 --- a/client.go +++ b/client.go @@ -249,7 +249,7 @@ type ClientOptions struct { // // By default, this ignores 404 status codes. // - // ⚠️ IMPORTANT: to not ignore any status codes, the option should be an empty slice and not nil. The nil option is + // IMPORTANT: to not ignore any status codes, the option should be an empty slice and not nil. The nil option is // used for defaulting to 404 ignores. TraceIgnoreStatusCodes [][]int }