Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,9 @@ def _fill_sample_rand(self):
)
return

self.dynamic_sampling_context["sample_rand"] = f"{sample_rand:.6f}" # noqa: E231
self.dynamic_sampling_context["sample_rand"] = (
f"{sample_rand:.6f}" # noqa: E231
)

def _sample_rand(self):
# type: () -> Optional[str]
Expand Down
23 changes: 12 additions & 11 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

from typing import TYPE_CHECKING

_DIST_SITE_PACKAGES_RE = re.compile(r"[\\/](?:dist|site)-packages[\\/]")

if TYPE_CHECKING:
from types import FrameType, TracebackType
from typing import (
Expand All @@ -45,9 +47,7 @@
ContextManager,
Dict,
Iterator,
List,
NoReturn,
Optional,
overload,
ParamSpec,
Set,
Expand Down Expand Up @@ -1150,15 +1150,18 @@ def event_from_exception(

def _module_in_list(name, items):
# type: (Optional[str], Optional[List[str]]) -> bool
if name is None:
if name is None or not items:
return False

if not items:
return False
# Use set for fast exact matching
items_set = set(items)
if name in items_set:
return True

for item in items:
if item == name or name.startswith(item + "."):
return True
# Prepare prefixes for startswith check
prefixes = tuple(f"{item}." for item in items)
if prefixes and name.startswith(prefixes):
return True

return False

Expand All @@ -1169,9 +1172,7 @@ def _is_external_source(abs_path):
if abs_path is None:
return False

external_source = (
re.search(r"[\\/](?:dist|site)-packages[\\/]", abs_path) is not None
)
external_source = _DIST_SITE_PACKAGES_RE.search(abs_path) is not None
return external_source


Expand Down