Skip to content
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

[do not merge] Only mark frame as in_app if explicitly set by user #3984

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,19 +1076,6 @@ def set_in_app_in_frames(frames, in_app_exclude, in_app_include, project_root=No
frame["in_app"] = False
continue

# if frame has no abs_path, skip further checks
abs_path = frame.get("abs_path")
if abs_path is None:
continue

if _is_external_source(abs_path):
frame["in_app"] = False
continue

if _is_in_project_root(abs_path, project_root):
frame["in_app"] = True
continue

return frames


Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/aws_lambda/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_handler(event, context):
assert frame1["abs_path"] == "/var/task/test_lambda.py"
assert frame1["function"] == "test_handler"

assert frame1["in_app"] is True
assert "in_app" not in frame1

assert exception["mechanism"]["type"] == "aws_lambda"
assert not exception["mechanism"]["handled"]
Expand Down
1 change: 0 additions & 1 deletion tests/new_scopes_compat/test_new_scopes_compat_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def create_expected_error_event(trx, span):
"vars": {
"ex": mock.ANY,
},
"in_app": True,
}
]
},
Expand Down
84 changes: 2 additions & 82 deletions tests/utils/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,16 @@ def test_parse_invalid_dsn(dsn):


@pytest.mark.parametrize(
"frame,in_app_include,in_app_exclude,project_root,resulting_frame",
"frame,in_app_include,in_app_exclude,resulting_frame",
[
[
{
"abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py",
},
None,
None,
None,
{
"abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py",
"in_app": False,
},
],
[
Expand All @@ -142,11 +140,9 @@ def test_parse_invalid_dsn(dsn):
},
None,
None,
None,
{
"module": "fastapi.routing",
"abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py",
"in_app": False,
},
],
[
Expand All @@ -157,7 +153,6 @@ def test_parse_invalid_dsn(dsn):
},
None,
None,
None,
{
"module": "fastapi.routing",
"abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py",
Expand All @@ -170,10 +165,8 @@ def test_parse_invalid_dsn(dsn):
},
None,
None,
None,
{
"abs_path": "C:\\Users\\winuser\\AppData\\Roaming\\Python\\Python35\\site-packages\\fastapi\\routing.py",
"in_app": False,
},
],
[
Expand All @@ -183,11 +176,9 @@ def test_parse_invalid_dsn(dsn):
},
None,
None,
None,
{
"module": "fastapi.routing",
"abs_path": "/usr/lib/python2.7/dist-packages/fastapi/routing.py",
"in_app": False,
},
],
[
Expand All @@ -196,7 +187,6 @@ def test_parse_invalid_dsn(dsn):
},
None,
None,
None,
{
"abs_path": "/home/ubuntu/fastapi/main.py",
},
Expand All @@ -208,7 +198,6 @@ def test_parse_invalid_dsn(dsn):
},
None,
None,
None,
{
"module": "main",
"abs_path": "/home/ubuntu/fastapi/main.py",
Expand All @@ -221,10 +210,8 @@ def test_parse_invalid_dsn(dsn):
},
["fastapi"],
None,
None,
{
"abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py",
"in_app": False, # because there is no module set
},
],
[
Expand All @@ -234,7 +221,6 @@ def test_parse_invalid_dsn(dsn):
},
["fastapi"],
None,
None,
{
"module": "fastapi.routing",
"abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py",
Expand All @@ -249,7 +235,6 @@ def test_parse_invalid_dsn(dsn):
},
["fastapi"],
None,
None,
{
"module": "fastapi.routing",
"abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py",
Expand All @@ -262,10 +247,8 @@ def test_parse_invalid_dsn(dsn):
},
["fastapi"],
None,
None,
{
"abs_path": "C:\\Users\\winuser\\AppData\\Roaming\\Python\\Python35\\site-packages\\fastapi\\routing.py",
"in_app": False, # because there is no module set
},
],
[
Expand All @@ -275,7 +258,6 @@ def test_parse_invalid_dsn(dsn):
},
["fastapi"],
None,
None,
{
"module": "fastapi.routing",
"abs_path": "/usr/lib/python2.7/dist-packages/fastapi/routing.py",
Expand All @@ -288,7 +270,6 @@ def test_parse_invalid_dsn(dsn):
},
["fastapi"],
None,
None,
{
"abs_path": "/home/ubuntu/fastapi/main.py",
},
Expand All @@ -300,7 +281,6 @@ def test_parse_invalid_dsn(dsn):
},
["fastapi"],
None,
None,
{
"module": "main",
"abs_path": "/home/ubuntu/fastapi/main.py",
Expand All @@ -313,10 +293,8 @@ def test_parse_invalid_dsn(dsn):
},
None,
["main"],
None,
{
"abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py",
"in_app": False,
},
],
[
Expand All @@ -326,11 +304,9 @@ def test_parse_invalid_dsn(dsn):
},
None,
["main"],
None,
{
"module": "fastapi.routing",
"abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py",
"in_app": False,
},
],
[
Expand All @@ -341,7 +317,6 @@ def test_parse_invalid_dsn(dsn):
},
None,
["main"],
None,
{
"module": "fastapi.routing",
"abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py",
Expand All @@ -354,10 +329,8 @@ def test_parse_invalid_dsn(dsn):
},
None,
["main"],
None,
{
"abs_path": "C:\\Users\\winuser\\AppData\\Roaming\\Python\\Python35\\site-packages\\fastapi\\routing.py",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually partially answers a question I had, which is how windows paths get reported. Is it safe to assume that if the paths in the frames are reported with the C: and with double backslashes, the project root will be, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd guess so -- if the two didn't match then the is-in-project-root check would never be correct.

"in_app": False,
},
],
[
Expand All @@ -367,11 +340,9 @@ def test_parse_invalid_dsn(dsn):
},
None,
["main"],
None,
{
"module": "fastapi.routing",
"abs_path": "/usr/lib/python2.7/dist-packages/fastapi/routing.py",
"in_app": False,
},
],
[
Expand All @@ -380,7 +351,6 @@ def test_parse_invalid_dsn(dsn):
},
None,
["main"],
None,
{
"abs_path": "/home/ubuntu/fastapi/main.py",
},
Expand All @@ -392,7 +362,6 @@ def test_parse_invalid_dsn(dsn):
},
None,
["main"],
None,
{
"module": "main",
"abs_path": "/home/ubuntu/fastapi/main.py",
Expand All @@ -405,7 +374,6 @@ def test_parse_invalid_dsn(dsn):
},
None,
None,
None,
{
"module": "fastapi.routing",
},
Expand All @@ -416,7 +384,6 @@ def test_parse_invalid_dsn(dsn):
},
["fastapi"],
None,
None,
{
"module": "fastapi.routing",
"in_app": True,
Expand All @@ -428,65 +395,18 @@ def test_parse_invalid_dsn(dsn):
},
None,
["fastapi"],
None,
{
"module": "fastapi.routing",
"in_app": False,
},
],
# with project_root set
[
{
"module": "main",
"abs_path": "/home/ubuntu/fastapi/main.py",
},
None,
None,
"/home/ubuntu/fastapi",
{
"module": "main",
"abs_path": "/home/ubuntu/fastapi/main.py",
"in_app": True,
},
],
[
{
"module": "main",
"abs_path": "/home/ubuntu/fastapi/main.py",
},
["main"],
None,
"/home/ubuntu/fastapi",
{
"module": "main",
"abs_path": "/home/ubuntu/fastapi/main.py",
"in_app": True,
},
],
[
{
"module": "main",
"abs_path": "/home/ubuntu/fastapi/main.py",
},
None,
["main"],
"/home/ubuntu/fastapi",
{
"module": "main",
"abs_path": "/home/ubuntu/fastapi/main.py",
"in_app": False,
},
],
],
)
def test_set_in_app_in_frames(
frame, in_app_include, in_app_exclude, project_root, resulting_frame
):
def test_set_in_app_in_frames(frame, in_app_include, in_app_exclude, resulting_frame):
new_frames = set_in_app_in_frames(
[frame],
in_app_include=in_app_include,
in_app_exclude=in_app_exclude,
project_root=project_root,
)

assert new_frames[0] == resulting_frame
Expand Down
Loading