diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index 150e73661e..787068560f 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -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) ) diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 4d07974809..7907b99149 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -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 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 @@ -1118,18 +1120,18 @@ def event_from_exception( def _module_in_list(name, items): - # 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): diff --git a/tests/utils/test_general.py b/tests/utils/test_general.py index 1b689ec735..5e5160f095 100644 --- a/tests/utils/test_general.py +++ b/tests/utils/test_general.py @@ -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", }, ], [ @@ -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", }, ], [ @@ -420,6 +422,7 @@ def test_parse_invalid_dsn(dsn): { "module": "fastapi.routing", "in_app": True, + "in_app_include_used": "fastapi", }, ], [ @@ -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", }, ], [