Skip to content
Closed
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
7 changes: 4 additions & 3 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@ def _should_be_included(
# type: (...) -> bool
# in_app_include takes precedence over in_app_exclude
should_be_included = _module_in_list(namespace, in_app_include)
should_be_excluded = _is_external_source(abs_path) or _module_in_list(
namespace, in_app_exclude
should_be_excluded = (
_is_external_source(abs_path)
or _module_in_list(namespace, in_app_exclude) is not None
)
return not is_sentry_sdk_frame and (
should_be_included
should_be_included is not None
or (_is_in_project_root(abs_path, project_root) and not should_be_excluded)
)

Expand Down
16 changes: 9 additions & 7 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,12 +1042,14 @@ def set_in_app_in_frames(frames, in_app_exclude, in_app_include, project_root=No
module = frame.get("module")

# check if module in frame is in the list of modules to include
if _module_in_list(module, in_app_include):
include_pattern_matched = _module_in_list(module, in_app_include)
if include_pattern_matched:
frame["in_app"] = True
frame["in_app_include_used"] = include_pattern_matched
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why store this info for an include but not for an exclude?

continue

# check if module in frame is in the list of modules to exclude
if _module_in_list(module, in_app_exclude):
if _module_in_list(module, in_app_exclude) is not None:
frame["in_app"] = False
continue

Expand Down Expand Up @@ -1118,18 +1120,18 @@ def event_from_exception(


def _module_in_list(name, items):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change the name of this function to better match it's new job - something like _find_module_match_in_list or some such?

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

if not items:
return False
return None

for item in items:
if item == name or name.startswith(item + "."):
return True
return item

return False
return None


def _is_external_source(abs_path):
Expand Down
4 changes: 4 additions & 0 deletions tests/utils/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ def test_parse_invalid_dsn(dsn):
"module": "fastapi.routing",
"abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py",
"in_app": True,
"in_app_include_used": "fastapi",
},
],
[
Expand Down Expand Up @@ -280,6 +281,7 @@ def test_parse_invalid_dsn(dsn):
"module": "fastapi.routing",
"abs_path": "/usr/lib/python2.7/dist-packages/fastapi/routing.py",
"in_app": True,
"in_app_include_used": "fastapi",
},
],
[
Expand Down Expand Up @@ -420,6 +422,7 @@ def test_parse_invalid_dsn(dsn):
{
"module": "fastapi.routing",
"in_app": True,
"in_app_include_used": "fastapi",
},
],
[
Expand Down Expand Up @@ -461,6 +464,7 @@ def test_parse_invalid_dsn(dsn):
"module": "main",
"abs_path": "/home/ubuntu/fastapi/main.py",
"in_app": True,
"in_app_include_used": "main",
},
],
[
Expand Down
Loading