Skip to content

Commit

Permalink
fix(tracing): Fix add_query_source with modules outside of project …
Browse files Browse the repository at this point in the history
…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).
  • Loading branch information
rominf committed Aug 27, 2024
1 parent f8e520a commit 6fa39db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
16 changes: 7 additions & 9 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,13 @@ def _should_be_included(
project_root: Optional[str],
) -> bool:
# in_app_include takes precedence over in_app_exclude
should_be_included = (
not (
_is_external_source(abs_path) or _module_in_list(namespace, in_app_exclude)
)
) or _module_in_list(namespace, in_app_include)
return (
_is_in_project_root(abs_path, project_root)
and should_be_included
and not is_sentry_sdk_frame
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
)
return not is_sentry_sdk_frame and (
should_be_included
or (_is_in_project_root(abs_path, project_root) and not should_be_excluded)
)


Expand Down
5 changes: 1 addition & 4 deletions tests/test_tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ShouldBeIncludedTestCase:
),
False,
),
pytest.param(
(
ShouldBeIncludedTestCase(
id="Frame from system-wide installed Django with `django` in `in_app_include`",
is_sentry_sdk_frame=False,
Expand All @@ -83,9 +83,6 @@ class ShouldBeIncludedTestCase:
in_app_include=["django"],
),
True,
marks=pytest.mark.xfail(
reason="Bug, see https://github.com/getsentry/sentry-python/issues/3312"
),
),
],
ids=id_function,
Expand Down

0 comments on commit 6fa39db

Please sign in to comment.