diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index d99ad7b9a4..1c7da7cc7a 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -22,6 +22,7 @@ is_sentry_url, _is_external_source, _module_in_list, + _is_in_project_root, ) from sentry_sdk._types import TYPE_CHECKING @@ -218,20 +219,14 @@ def add_query_source(span): is_sentry_sdk_frame = namespace is not None and namespace.startswith( "sentry_sdk." ) + 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_included = not _is_external_source(abs_path) - if namespace is not None: - if in_app_exclude and _module_in_list(namespace, in_app_exclude): - should_be_included = False - if in_app_include and _module_in_list(namespace, in_app_include): - # in_app_include takes precedence over in_app_exclude, so doing it - # at the end - should_be_included = True - - if ( - abs_path.startswith(project_root) - and should_be_included - and not is_sentry_sdk_frame + if not is_sentry_sdk_frame and ( + should_be_included + or (_is_in_project_root(abs_path, project_root) and not should_be_excluded) ): break diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 8a805d3d64..b9749c503f 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -1043,7 +1043,7 @@ def event_from_exception( def _module_in_list(name, items): - # type: (str, Optional[List[str]]) -> bool + # type: (Optional[str], Optional[List[str]]) -> bool if name is None: return False