From 37633bc9b6d9f19a87dc423ce15f7d89cec0d36d Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 14 Jan 2025 15:16:10 +0100 Subject: [PATCH 1/3] Added deprecation warning --- sentry_sdk/api.py | 4 ++++ sentry_sdk/tracing.py | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/sentry_sdk/api.py b/sentry_sdk/api.py index d60434079c..1b5acd274a 100644 --- a/sentry_sdk/api.py +++ b/sentry_sdk/api.py @@ -388,6 +388,10 @@ def start_transaction( def set_measurement(name, value, unit=""): # type: (str, float, MeasurementUnit) -> None + """ + .. deprecated:: 2.21.0 + This function is deprecated and will be removed in the next major release. + """ transaction = get_current_scope().transaction if transaction is not None: transaction.set_measurement(name, value, unit) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 3868b2e6c8..e05de9fdd5 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -585,6 +585,11 @@ def set_status(self, value): def set_measurement(self, name, value, unit=""): # type: (str, float, MeasurementUnit) -> None + warnings.warn( + "`set_measurement()` is deprecated and will be removed in the next major version. Please use `set_data()` instead.", + DeprecationWarning, + stacklevel=2, + ) self._measurements[name] = {"value": value, "unit": unit} def set_thread(self, thread_id, thread_name): @@ -1013,6 +1018,11 @@ def finish( def set_measurement(self, name, value, unit=""): # type: (str, float, MeasurementUnit) -> None + warnings.warn( + "`set_measurement()` is deprecated and will be removed in the next major version. Please use `set_data()` instead.", + DeprecationWarning, + stacklevel=2, + ) self._measurements[name] = {"value": value, "unit": unit} def set_context(self, key, value): From ca12f384f8bc5ddfd4bb9474d83387936f7b13e5 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 14 Jan 2025 15:49:02 +0100 Subject: [PATCH 2/3] Test for deprecation message --- tests/tracing/test_misc.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/tracing/test_misc.py b/tests/tracing/test_misc.py index de2f782538..ca7580614a 100644 --- a/tests/tracing/test_misc.py +++ b/tests/tracing/test_misc.py @@ -295,6 +295,21 @@ def test_set_meaurement_public_api(sentry_init, capture_events): assert event["measurements"]["metric.bar"] == {"value": 456, "unit": "second"} +def test_set_measurement_deprecated(sentry_init): + sentry_init(traces_sample_rate=1.0) + + with start_transaction(name="measuring stuff") as trx: + with pytest.warns(DeprecationWarning): + set_measurement("metric.foo", 123) + + with pytest.warns(DeprecationWarning): + trx.set_measurement("metric.bar", 456) + + with start_span(op="measuring span") as span: + with pytest.warns(DeprecationWarning): + span.set_measurement("metric.baz", 420.69, unit="custom") + + @pytest.mark.parametrize( "trace_propagation_targets,url,expected_propagation_decision", [ From 533a95b1661a006a9a10d77047eab75352869151 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 15 Jan 2025 09:34:51 +0100 Subject: [PATCH 3/3] Some test --- tests/tracing/test_misc.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/tracing/test_misc.py b/tests/tracing/test_misc.py index ca7580614a..b813ebc7ce 100644 --- a/tests/tracing/test_misc.py +++ b/tests/tracing/test_misc.py @@ -310,6 +310,29 @@ def test_set_measurement_deprecated(sentry_init): span.set_measurement("metric.baz", 420.69, unit="custom") +def test_set_meaurement_compared_to_set_data(sentry_init, capture_events): + """ + This is just a test to see if we can use set_data() instead of set_measurement() with + the same result in the backend. + """ + sentry_init(traces_sample_rate=1.0) + + events = capture_events() + + with start_transaction(name="measuring stuff") as transaction: + transaction.set_measurement("metric.foo", 123) + transaction.set_data("metric.bar", 456) + with start_span(op="measuring span") as span: + span.set_measurement("metric.baz", 420.69, unit="custom") + span.set_data("metric.qux", 789) + + (event,) = events + from pprint import pprint + + pprint(event) + raise AssertionError("This test is not finished yet.") + + @pytest.mark.parametrize( "trace_propagation_targets,url,expected_propagation_decision", [