Skip to content

Commit 6fa39db

Browse files
committed
fix(tracing): Fix add_query_source with modules outside of project root
Fix: #3312 Previously, when packages added in `in_app_include` were installed to a location outside of the project root directory, span from those packages were not extended with OTel compatible source code information. Cases include running Python from virtualenv created outside of the project root directory or Python packages installed into the system using package managers. This resulted in an inconsistency: spans from the same project would be different, depending on the deployment method. In this change, the logic was slightly changed to avoid these discrepancies and conform to the requirements, described in the PR with better setting of in-app in stack frames: #1894 (comment).
1 parent f8e520a commit 6fa39db

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

sentry_sdk/tracing_utils.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,13 @@ def _should_be_included(
188188
project_root: Optional[str],
189189
) -> bool:
190190
# in_app_include takes precedence over in_app_exclude
191-
should_be_included = (
192-
not (
193-
_is_external_source(abs_path) or _module_in_list(namespace, in_app_exclude)
194-
)
195-
) or _module_in_list(namespace, in_app_include)
196-
return (
197-
_is_in_project_root(abs_path, project_root)
198-
and should_be_included
199-
and not is_sentry_sdk_frame
191+
should_be_included = _module_in_list(namespace, in_app_include)
192+
should_be_excluded = _is_external_source(abs_path) or _module_in_list(
193+
namespace, in_app_exclude
194+
)
195+
return not is_sentry_sdk_frame and (
196+
should_be_included
197+
or (_is_in_project_root(abs_path, project_root) and not should_be_excluded)
200198
)
201199

202200

tests/test_tracing_utils.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ShouldBeIncludedTestCase:
7373
),
7474
False,
7575
),
76-
pytest.param(
76+
(
7777
ShouldBeIncludedTestCase(
7878
id="Frame from system-wide installed Django with `django` in `in_app_include`",
7979
is_sentry_sdk_frame=False,
@@ -83,9 +83,6 @@ class ShouldBeIncludedTestCase:
8383
in_app_include=["django"],
8484
),
8585
True,
86-
marks=pytest.mark.xfail(
87-
reason="Bug, see https://github.com/getsentry/sentry-python/issues/3312"
88-
),
8986
),
9087
],
9188
ids=id_function,

0 commit comments

Comments
 (0)