From 228a965af15ff94daa5470238c56b144f1016049 Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Thu, 19 Jan 2023 13:36:05 -0500 Subject: [PATCH] fix(profiling): Defaul in_app decision to None Currently, the SDK marks all frames as in_app when it can't find any in_app frames. As we try to move some of this detection server side, we still want to allow the end user to overwrite the decision client side. So we'll leave in_app as `None` to indicate the server should decide of the frame is in_app. --- sentry_sdk/profiler.py | 5 ++++- sentry_sdk/utils.py | 6 +++--- tests/utils/test_general.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/sentry_sdk/profiler.py b/sentry_sdk/profiler.py index 884fb70af5..b89075ef1b 100644 --- a/sentry_sdk/profiler.py +++ b/sentry_sdk/profiler.py @@ -439,7 +439,10 @@ def to_json(self, event_opt, options): profile = self.process() handle_in_app_impl( - profile["frames"], options["in_app_exclude"], options["in_app_include"] + profile["frames"], + options["in_app_exclude"], + options["in_app_include"], + default_in_app=False, # Do not default a frame to `in_app: True` ) return { diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 4d6a091398..19b3dced5d 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -755,8 +755,8 @@ def handle_in_app(event, in_app_exclude=None, in_app_include=None): return event -def handle_in_app_impl(frames, in_app_exclude, in_app_include): - # type: (Any, Optional[List[str]], Optional[List[str]]) -> Optional[Any] +def handle_in_app_impl(frames, in_app_exclude, in_app_include, default_in_app=True): + # type: (Any, Optional[List[str]], Optional[List[str]], bool) -> Optional[Any] if not frames: return None @@ -777,7 +777,7 @@ def handle_in_app_impl(frames, in_app_exclude, in_app_include): elif _module_in_set(module, in_app_exclude): frame["in_app"] = False - if not any_in_app: + if default_in_app and not any_in_app: for frame in frames: if frame.get("in_app") is None: frame["in_app"] = True diff --git a/tests/utils/test_general.py b/tests/utils/test_general.py index f2d0069ba3..f84f6053cb 100644 --- a/tests/utils/test_general.py +++ b/tests/utils/test_general.py @@ -154,6 +154,22 @@ def test_in_app(empty): ) == [{"module": "foo", "in_app": False}, {"module": "bar", "in_app": True}] +def test_default_in_app(): + assert handle_in_app_impl( + [{"module": "foo"}, {"module": "bar"}], in_app_include=None, in_app_exclude=None + ) == [ + {"module": "foo", "in_app": True}, + {"module": "bar", "in_app": True}, + ] + + assert handle_in_app_impl( + [{"module": "foo"}, {"module": "bar"}], + in_app_include=None, + in_app_exclude=None, + default_in_app=False, + ) == [{"module": "foo"}, {"module": "bar"}] + + def test_iter_stacktraces(): assert set( iter_event_stacktraces(