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

fix(profiling): Resolve inherited method class names #1756

Merged
merged 1 commit into from Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions sentry_sdk/profiler.py
Expand Up @@ -211,7 +211,9 @@ def get_frame_name(frame):
and f_code.co_varnames[0] == "self"
and "self" in frame.f_locals
):
return "{}.{}".format(frame.f_locals["self"].__class__.__name__, name)
for cls in frame.f_locals["self"].__class__.__mro__:
if name in cls.__dict__:
return "{}.{}".format(cls.__name__, name)
except AttributeError:
pass

Expand All @@ -225,7 +227,9 @@ def get_frame_name(frame):
and f_code.co_varnames[0] == "cls"
and "cls" in frame.f_locals
):
return "{}.{}".format(frame.f_locals["cls"].__name__, name)
for cls in frame.f_locals["cls"].__mro__:
if name in cls.__dict__:
return "{}.{}".format(cls.__name__, name)
except AttributeError:
pass

Expand Down
56 changes: 55 additions & 1 deletion tests/test_profiler.py
Expand Up @@ -82,7 +82,35 @@ def get_frame(depth=1):
return inspect.currentframe()


class GetFrame:
class GetFrameBase:
def inherited_instance_method(self):
return inspect.currentframe()

def inherited_instance_method_wrapped(self):
def wrapped():
self
return inspect.currentframe()

return wrapped

@classmethod
def inherited_class_method(cls):
return inspect.currentframe()

@classmethod
def inherited_class_method_wrapped(cls):
def wrapped():
cls
return inspect.currentframe()

return wrapped

@staticmethod
def inherited_static_method():
return inspect.currentframe()


class GetFrame(GetFrameBase):
def instance_method(self):
return inspect.currentframe()

Expand Down Expand Up @@ -149,6 +177,32 @@ def static_method():
id="static_method",
marks=pytest.mark.skip(reason="unsupported"),
),
pytest.param(
GetFrame().inherited_instance_method(),
"GetFrameBase.inherited_instance_method",
id="inherited_instance_method",
),
pytest.param(
GetFrame().inherited_instance_method_wrapped()(),
"wrapped",
id="instance_method_wrapped",
),
pytest.param(
GetFrame().inherited_class_method(),
"GetFrameBase.inherited_class_method",
id="inherited_class_method",
),
pytest.param(
GetFrame().inherited_class_method_wrapped()(),
"wrapped",
id="inherited_class_method_wrapped",
),
pytest.param(
GetFrame().inherited_static_method(),
"GetFrameBase.static_method",
id="inherited_static_method",
marks=pytest.mark.skip(reason="unsupported"),
),
],
)
def test_get_frame_name(frame, frame_name):
Expand Down