-
Notifications
You must be signed in to change notification settings - Fork 553
fix(tracing): Fix add_query_source
with modules outside of project root
#3313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sentrivana
merged 5 commits into
getsentry:master
from
rominf:rominf-tracing-fix-logic-in_app
Oct 1, 2024
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e3bb1c0
ref(tracing): Move `should_be_included` logic into function
rominf c6ce9c7
fix(tracing): Fix `add_query_source` with modules outside of project …
rominf b7c382f
ref(tracing_utils): Use type comments instead of type annotations
szokeasaurusrex 2c41170
Merge branch 'master' into rominf-tracing-fix-logic-in_app
szokeasaurusrex 7751e5d
Merge branch 'master' into rominf-tracing-fix-logic-in_app
sentrivana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from dataclasses import asdict, dataclass | ||
from typing import Optional, List, Any | ||
|
||
from sentry_sdk.tracing_utils import _should_be_included | ||
import pytest | ||
|
||
|
||
def id_function(val: Any) -> str: | ||
if isinstance(val, ShouldBeIncludedTestCase): | ||
return val.id | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ShouldBeIncludedTestCase: | ||
id: str | ||
is_sentry_sdk_frame: bool | ||
namespace: Optional[str] = None | ||
in_app_include: Optional[List[str]] = None | ||
in_app_exclude: Optional[List[str]] = None | ||
abs_path: Optional[str] = None | ||
project_root: Optional[str] = None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_case, expected", | ||
[ | ||
( | ||
ShouldBeIncludedTestCase( | ||
id="Frame from Sentry SDK", | ||
is_sentry_sdk_frame=True, | ||
), | ||
False, | ||
), | ||
( | ||
ShouldBeIncludedTestCase( | ||
id="Frame from Django installed in virtualenv inside project root", | ||
is_sentry_sdk_frame=False, | ||
abs_path="/home/username/some_project/.venv/lib/python3.12/site-packages/django/db/models/sql/compiler", | ||
project_root="/home/username/some_project", | ||
namespace="django.db.models.sql.compiler", | ||
in_app_include=["django"], | ||
), | ||
True, | ||
), | ||
( | ||
ShouldBeIncludedTestCase( | ||
id="Frame from project", | ||
is_sentry_sdk_frame=False, | ||
abs_path="/home/username/some_project/some_project/__init__.py", | ||
project_root="/home/username/some_project", | ||
namespace="some_project", | ||
), | ||
True, | ||
), | ||
( | ||
ShouldBeIncludedTestCase( | ||
id="Frame from project module in `in_app_exclude`", | ||
is_sentry_sdk_frame=False, | ||
abs_path="/home/username/some_project/some_project/exclude_me/some_module.py", | ||
project_root="/home/username/some_project", | ||
namespace="some_project.exclude_me.some_module", | ||
in_app_exclude=["some_project.exclude_me"], | ||
), | ||
False, | ||
), | ||
( | ||
ShouldBeIncludedTestCase( | ||
id="Frame from system-wide installed Django", | ||
is_sentry_sdk_frame=False, | ||
abs_path="/usr/lib/python3.12/site-packages/django/db/models/sql/compiler", | ||
project_root="/home/username/some_project", | ||
namespace="django.db.models.sql.compiler", | ||
), | ||
False, | ||
), | ||
( | ||
ShouldBeIncludedTestCase( | ||
id="Frame from system-wide installed Django with `django` in `in_app_include`", | ||
is_sentry_sdk_frame=False, | ||
abs_path="/usr/lib/python3.12/site-packages/django/db/models/sql/compiler", | ||
project_root="/home/username/some_project", | ||
namespace="django.db.models.sql.compiler", | ||
in_app_include=["django"], | ||
), | ||
True, | ||
), | ||
], | ||
ids=id_function, | ||
) | ||
def test_should_be_included( | ||
test_case: ShouldBeIncludedTestCase, expected: bool | ||
) -> None: | ||
"""Checking logic, see: https://github.com/getsentry/sentry-python/issues/3312""" | ||
kwargs = asdict(test_case) | ||
kwargs.pop("id") | ||
assert _should_be_included(**kwargs) == expected |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.