Skip to content

Commit 84ef52a

Browse files
change option type to set
1 parent ed08547 commit 84ef52a

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

sentry_sdk/consts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class CompressionAlgo(Enum):
4040
from typing import Any
4141
from typing import Sequence
4242
from typing import Tuple
43+
from typing import AbstractSet
4344
from typing_extensions import Literal
4445
from typing_extensions import TypedDict
4546

@@ -919,7 +920,7 @@ def __init__(
919920
max_stack_frames=DEFAULT_MAX_STACK_FRAMES, # type: Optional[int]
920921
enable_logs=False, # type: bool
921922
before_send_log=None, # type: Optional[Callable[[Log, Hint], Optional[Log]]]
922-
trace_ignore_status_codes=[], # type: Sequence[Union[int, Tuple[int, int]]]
923+
trace_ignore_status_codes=frozenset(), # type: AbstractSet[int]
923924
):
924925
# type: (...) -> None
925926
"""Initialize the Sentry SDK with the given parameters. All parameters described here can be used in a call to `sentry_sdk.init()`.

sentry_sdk/tracing.py

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from typing import Tuple
3131
from typing import Union
3232
from typing import TypeVar
33-
from typing import Sequence
33+
from typing import Set
3434

3535
from typing_extensions import TypedDict, Unpack
3636

@@ -971,29 +971,6 @@ def _get_scope_from_finish_args(
971971

972972
return scope_or_hub
973973

974-
def _in_http_status_code_range(self, code, code_ranges):
975-
# type: (int, Sequence[Union[int, Tuple[int, int]]]) -> bool
976-
for target in code_ranges:
977-
if isinstance(target, int):
978-
if code == target:
979-
return True
980-
continue
981-
982-
wrong_type_message = "trace_ignore_status_codes must be a list of integers or pairs of integers."
983-
try:
984-
low, high = target
985-
if not isinstance(low, int) or not isinstance(high, int):
986-
logger.warning(wrong_type_message)
987-
continue
988-
989-
if low <= code <= high:
990-
return True
991-
992-
except Exception:
993-
logger.warning(wrong_type_message)
994-
995-
return False
996-
997974
def _get_log_representation(self):
998975
# type: () -> str
999976
return "{op}transaction <{name}>".format(
@@ -1074,9 +1051,9 @@ def finish(
10741051
logger.warning(
10751052
f"Invalid type for http.response.status_code; is {status_code!r} of type {type(status_code)}, expected an int."
10761053
)
1077-
elif status_code is not None and self._in_http_status_code_range(
1078-
status_code,
1079-
client.options["trace_ignore_status_codes"],
1054+
elif (
1055+
status_code is not None
1056+
and status_code in client.options["trace_ignore_status_codes"]
10801057
):
10811058
logger.debug(
10821059
"[Tracing] Discarding {transaction_description} because the HTTP status code {status_code} is matched by trace_ignore_status_codes: {trace_ignore_status_codes}".format(

0 commit comments

Comments
 (0)