Skip to content

Deprecate set_measurement() API. #3934

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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,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):
Expand Down Expand Up @@ -1049,6 +1054,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):
Expand Down
38 changes: 38 additions & 0 deletions tests/tracing/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,44 @@ 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")


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",
[
Expand Down
Loading