From 849bfdde7b07f2db5baf36399720e828d4c5fb5c Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Tue, 21 Jan 2025 11:31:53 +0100 Subject: [PATCH 1/4] Only mark frame as in_app if explicitly set by user --- sentry_sdk/utils.py | 13 ------- tests/utils/test_general.py | 74 +------------------------------------ 2 files changed, 2 insertions(+), 85 deletions(-) diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 0fead48377..7b73800f0e 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -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 diff --git a/tests/utils/test_general.py b/tests/utils/test_general.py index 1b689ec735..c6b8fdbf7b 100644 --- a/tests/utils/test_general.py +++ b/tests/utils/test_general.py @@ -121,7 +121,7 @@ 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", [ [ { @@ -129,7 +129,6 @@ def test_parse_invalid_dsn(dsn): }, None, None, - None, { "abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py", "in_app": False, @@ -142,7 +141,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", @@ -157,7 +155,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", @@ -170,7 +167,6 @@ 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, @@ -183,7 +179,6 @@ def test_parse_invalid_dsn(dsn): }, None, None, - None, { "module": "fastapi.routing", "abs_path": "/usr/lib/python2.7/dist-packages/fastapi/routing.py", @@ -196,7 +191,6 @@ def test_parse_invalid_dsn(dsn): }, None, None, - None, { "abs_path": "/home/ubuntu/fastapi/main.py", }, @@ -208,7 +202,6 @@ def test_parse_invalid_dsn(dsn): }, None, None, - None, { "module": "main", "abs_path": "/home/ubuntu/fastapi/main.py", @@ -221,7 +214,6 @@ 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 @@ -234,7 +226,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", @@ -249,7 +240,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", @@ -262,7 +252,6 @@ 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 @@ -275,7 +264,6 @@ def test_parse_invalid_dsn(dsn): }, ["fastapi"], None, - None, { "module": "fastapi.routing", "abs_path": "/usr/lib/python2.7/dist-packages/fastapi/routing.py", @@ -288,7 +276,6 @@ def test_parse_invalid_dsn(dsn): }, ["fastapi"], None, - None, { "abs_path": "/home/ubuntu/fastapi/main.py", }, @@ -300,7 +287,6 @@ def test_parse_invalid_dsn(dsn): }, ["fastapi"], None, - None, { "module": "main", "abs_path": "/home/ubuntu/fastapi/main.py", @@ -313,7 +299,6 @@ 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, @@ -326,7 +311,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", @@ -341,7 +325,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", @@ -354,7 +337,6 @@ def test_parse_invalid_dsn(dsn): }, None, ["main"], - None, { "abs_path": "C:\\Users\\winuser\\AppData\\Roaming\\Python\\Python35\\site-packages\\fastapi\\routing.py", "in_app": False, @@ -367,7 +349,6 @@ def test_parse_invalid_dsn(dsn): }, None, ["main"], - None, { "module": "fastapi.routing", "abs_path": "/usr/lib/python2.7/dist-packages/fastapi/routing.py", @@ -380,7 +361,6 @@ def test_parse_invalid_dsn(dsn): }, None, ["main"], - None, { "abs_path": "/home/ubuntu/fastapi/main.py", }, @@ -392,7 +372,6 @@ def test_parse_invalid_dsn(dsn): }, None, ["main"], - None, { "module": "main", "abs_path": "/home/ubuntu/fastapi/main.py", @@ -405,7 +384,6 @@ def test_parse_invalid_dsn(dsn): }, None, None, - None, { "module": "fastapi.routing", }, @@ -416,7 +394,6 @@ def test_parse_invalid_dsn(dsn): }, ["fastapi"], None, - None, { "module": "fastapi.routing", "in_app": True, @@ -428,65 +405,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 From 85d75085de5d8ba391a23019588d0cc6454bb446 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Tue, 21 Jan 2025 12:03:44 +0100 Subject: [PATCH 2/4] fix test --- tests/utils/test_general.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/utils/test_general.py b/tests/utils/test_general.py index c6b8fdbf7b..e18c707f2f 100644 --- a/tests/utils/test_general.py +++ b/tests/utils/test_general.py @@ -131,7 +131,6 @@ def test_parse_invalid_dsn(dsn): None, { "abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py", - "in_app": False, }, ], [ @@ -144,7 +143,6 @@ def test_parse_invalid_dsn(dsn): { "module": "fastapi.routing", "abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py", - "in_app": False, }, ], [ @@ -169,7 +167,6 @@ def test_parse_invalid_dsn(dsn): None, { "abs_path": "C:\\Users\\winuser\\AppData\\Roaming\\Python\\Python35\\site-packages\\fastapi\\routing.py", - "in_app": False, }, ], [ @@ -182,7 +179,6 @@ def test_parse_invalid_dsn(dsn): { "module": "fastapi.routing", "abs_path": "/usr/lib/python2.7/dist-packages/fastapi/routing.py", - "in_app": False, }, ], [ @@ -216,7 +212,6 @@ def test_parse_invalid_dsn(dsn): None, { "abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py", - "in_app": False, # because there is no module set }, ], [ @@ -254,7 +249,6 @@ def test_parse_invalid_dsn(dsn): None, { "abs_path": "C:\\Users\\winuser\\AppData\\Roaming\\Python\\Python35\\site-packages\\fastapi\\routing.py", - "in_app": False, # because there is no module set }, ], [ @@ -301,7 +295,6 @@ def test_parse_invalid_dsn(dsn): ["main"], { "abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py", - "in_app": False, }, ], [ @@ -314,7 +307,6 @@ def test_parse_invalid_dsn(dsn): { "module": "fastapi.routing", "abs_path": "/home/ubuntu/fastapi/.venv/lib/python3.10/site-packages/fastapi/routing.py", - "in_app": False, }, ], [ @@ -339,7 +331,6 @@ def test_parse_invalid_dsn(dsn): ["main"], { "abs_path": "C:\\Users\\winuser\\AppData\\Roaming\\Python\\Python35\\site-packages\\fastapi\\routing.py", - "in_app": False, }, ], [ @@ -352,7 +343,6 @@ def test_parse_invalid_dsn(dsn): { "module": "fastapi.routing", "abs_path": "/usr/lib/python2.7/dist-packages/fastapi/routing.py", - "in_app": False, }, ], [ From e87775e1af79dfb41da8296e5727ca405c6d8f81 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Wed, 22 Jan 2025 14:29:46 +0100 Subject: [PATCH 3/4] . --- tests/new_scopes_compat/test_new_scopes_compat_event.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/new_scopes_compat/test_new_scopes_compat_event.py b/tests/new_scopes_compat/test_new_scopes_compat_event.py index db1e5fec4b..fb315a7bea 100644 --- a/tests/new_scopes_compat/test_new_scopes_compat_event.py +++ b/tests/new_scopes_compat/test_new_scopes_compat_event.py @@ -66,7 +66,6 @@ def create_expected_error_event(trx, span): "vars": { "ex": mock.ANY, }, - "in_app": True, } ] }, From df19ad8a186e21894b78bfc0b92f8bf6eaa634e8 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Wed, 22 Jan 2025 14:40:20 +0100 Subject: [PATCH 4/4] fix aws, too --- tests/integrations/aws_lambda/test_aws.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrations/aws_lambda/test_aws.py b/tests/integrations/aws_lambda/test_aws.py index f60bedc846..d5f896dcc8 100644 --- a/tests/integrations/aws_lambda/test_aws.py +++ b/tests/integrations/aws_lambda/test_aws.py @@ -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"]