From 9cd4d863d038a4ee9bbd88ee8dc24de8cfb9b6ce Mon Sep 17 00:00:00 2001 From: Jan Michael Auer Date: Tue, 28 Nov 2023 15:21:40 +0100 Subject: [PATCH 1/2] feat(metrics): Add source context to code locations --- sentry_sdk/metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/metrics.py b/sentry_sdk/metrics.py index d5b22b1e0e..a36cf7c812 100644 --- a/sentry_sdk/metrics.py +++ b/sentry_sdk/metrics.py @@ -76,7 +76,7 @@ def get_code_location(stacklevel): return None return serialize_frame( - frm, include_local_variables=False, include_source_context=False + frm, include_local_variables=False, include_source_context=True ) From fda14dfa4324a6a10d318ca367d11d004a75a0ff Mon Sep 17 00:00:00 2001 From: Jan Michael Auer Date: Tue, 28 Nov 2023 15:38:01 +0100 Subject: [PATCH 2/2] test: Update assertions --- tests/test_metrics.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_metrics.py b/tests/test_metrics.py index a7023cc033..15cfb9d37f 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -85,6 +85,9 @@ def test_incr(sentry_init, capture_envelopes): "function": sys._getframe().f_code.co_name, "module": __name__, "lineno": mock.ANY, + "pre_context": mock.ANY, + "context_line": mock.ANY, + "post_context": mock.ANY, } ] }, @@ -133,6 +136,9 @@ def test_timing(sentry_init, capture_envelopes): "function": sys._getframe().f_code.co_name, "module": __name__, "lineno": mock.ANY, + "pre_context": mock.ANY, + "context_line": mock.ANY, + "post_context": mock.ANY, } ] }, @@ -200,6 +206,9 @@ def amazing_nano(): "function": sys._getframe().f_code.co_name, "module": __name__, "lineno": mock.ANY, + "pre_context": mock.ANY, + "context_line": mock.ANY, + "post_context": mock.ANY, } ], "d:whatever-2@nanosecond": [ @@ -210,6 +219,9 @@ def amazing_nano(): "function": sys._getframe().f_code.co_name, "module": __name__, "lineno": mock.ANY, + "pre_context": mock.ANY, + "context_line": mock.ANY, + "post_context": mock.ANY, } ], }, @@ -261,6 +273,9 @@ def test_timing_basic(sentry_init, capture_envelopes): "function": sys._getframe().f_code.co_name, "module": __name__, "lineno": mock.ANY, + "pre_context": mock.ANY, + "context_line": mock.ANY, + "post_context": mock.ANY, } ] }, @@ -311,6 +326,9 @@ def test_distribution(sentry_init, capture_envelopes): "function": sys._getframe().f_code.co_name, "module": __name__, "lineno": mock.ANY, + "pre_context": mock.ANY, + "context_line": mock.ANY, + "post_context": mock.ANY, } ] }, @@ -360,6 +378,9 @@ def test_set(sentry_init, capture_envelopes): "function": sys._getframe().f_code.co_name, "module": __name__, "lineno": mock.ANY, + "pre_context": mock.ANY, + "context_line": mock.ANY, + "post_context": mock.ANY, } ] },