-
Notifications
You must be signed in to change notification settings - Fork 568
feat: Option to not trace HTTP requests based on status codes #4869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexander-alderman-webb
merged 21 commits into
master
from
webb/trace-ignore-status-codes-client-option
Oct 1, 2025
Merged
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
bbfb654
feat: Option to not trace HTTP requests based on status codes
alexander-alderman-webb 7cf3d7c
add debug log
alexander-alderman-webb 7bc4d62
improved validation
alexander-alderman-webb ad4e223
add type annotation
alexander-alderman-webb 7eeab46
improve range check
alexander-alderman-webb 7997870
.
alexander-alderman-webb 82e25d3
improve warning message
alexander-alderman-webb bcaa51f
add brackets to condition
alexander-alderman-webb 1423433
.
alexander-alderman-webb d62b438
add another test
alexander-alderman-webb 3492eea
.
alexander-alderman-webb 5374552
.
alexander-alderman-webb 74cde81
.
alexander-alderman-webb e851dfa
check not none
alexander-alderman-webb ed08547
Merge branch 'master' into webb/trace-ignore-status-codes-client-option
antonpirker 84ef52a
change option type to set
alexander-alderman-webb 88c84f4
update tests
alexander-alderman-webb 9395202
record lost events
alexander-alderman-webb ffb1d2d
simplify docstring
alexander-alderman-webb 6285feb
Merge branch 'master' into webb/trace-ignore-status-codes-client-option
alexander-alderman-webb 3f5a5bb
remove type check for http.response.status_code
alexander-alderman-webb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| import sentry_sdk | ||
| from sentry_sdk import start_transaction, start_span | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| def test_no_ignored_codes(sentry_init, capture_events): | ||
| sentry_init( | ||
| traces_sample_rate=1.0, | ||
| ) | ||
| events = capture_events() | ||
|
|
||
| with start_transaction(op="http", name="GET /"): | ||
| span_or_tx = sentry_sdk.get_current_span() | ||
| span_or_tx.set_data("http.response.status_code", 404) | ||
|
|
||
| assert len(events) == 1 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("status_code", [200, 404]) | ||
| def test_single_code_ignored(sentry_init, capture_events, status_code): | ||
| sentry_init( | ||
| traces_sample_rate=1.0, | ||
| trace_ignore_status_codes=(404,), | ||
| ) | ||
| events = capture_events() | ||
|
|
||
| with start_transaction(op="http", name="GET /"): | ||
| span_or_tx = sentry_sdk.get_current_span() | ||
| span_or_tx.set_data("http.response.status_code", status_code) | ||
|
|
||
| if status_code == 404: | ||
| assert not events | ||
| else: | ||
| assert len(events) == 1 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("status_code", [200, 305, 307, 399, 404]) | ||
| def test_range_ignored(sentry_init, capture_events, status_code): | ||
| sentry_init( | ||
| traces_sample_rate=1.0, | ||
| trace_ignore_status_codes=( | ||
| ( | ||
| 305, | ||
| 399, | ||
| ), | ||
| ), | ||
| ) | ||
| events = capture_events() | ||
|
|
||
| with start_transaction(op="http", name="GET /"): | ||
| span_or_tx = sentry_sdk.get_current_span() | ||
| span_or_tx.set_data("http.response.status_code", status_code) | ||
|
|
||
| if 305 <= status_code <= 399: | ||
| assert not events | ||
| else: | ||
| assert len(events) == 1 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("status_code", [200, 301, 303, 355, 404]) | ||
| def test_variety_ignored(sentry_init, capture_events, status_code): | ||
| sentry_init( | ||
| traces_sample_rate=1.0, | ||
| trace_ignore_status_codes=( | ||
| 301, | ||
| 302, | ||
| 303, | ||
| ( | ||
| 305, | ||
| 399, | ||
| ), | ||
| ( | ||
| 401, | ||
| 404, | ||
| ), | ||
| ), | ||
| ) | ||
| events = capture_events() | ||
|
|
||
| with start_transaction(op="http", name="GET /"): | ||
| span_or_tx = sentry_sdk.get_current_span() | ||
| span_or_tx.set_data("http.response.status_code", status_code) | ||
|
|
||
| if ( | ||
| 301 <= status_code <= 303 | ||
| or 305 <= status_code <= 399 | ||
| or 401 <= status_code <= 404 | ||
| ): | ||
| assert not events | ||
| else: | ||
| assert len(events) == 1 | ||
|
|
||
|
|
||
| def test_malformed_argument_ignored(sentry_init, capture_events): | ||
| sentry_init( | ||
| traces_sample_rate=1.0, | ||
| trace_ignore_status_codes=( | ||
| 404.0, | ||
| "404", | ||
| "401-404", | ||
| (404,), | ||
| ( | ||
| "401", | ||
| "404", | ||
| ), | ||
| ( | ||
| 401, | ||
| 404, | ||
| 500, | ||
| ), | ||
| ), | ||
| ) | ||
| events = capture_events() | ||
|
|
||
| with start_transaction(op="http", name="GET /"): | ||
| span_or_tx = sentry_sdk.get_current_span() | ||
| span_or_tx.set_data("http.response.status_code", 404) | ||
|
|
||
| assert len(events) == 1 | ||
|
|
||
|
|
||
| def test_transaction_not_ignored_when_status_code_has_invalid_type( | ||
| sentry_init, capture_events | ||
| ): | ||
| sentry_init( | ||
| traces_sample_rate=1.0, | ||
| trace_ignore_status_codes=((401, 404),), | ||
| ) | ||
| events = capture_events() | ||
|
|
||
| with start_transaction(op="http", name="GET /"): | ||
| span_or_tx = sentry_sdk.get_current_span() | ||
| span_or_tx.set_data("http.response.status_code", "404") | ||
|
|
||
| assert len(events) == 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.