Skip to content

Commit 6a1b263

Browse files
antonpirkerszokeasaurusrex
authored andcommitted
Remove usage of measurements in favor of span.data. (#92718)
Python SDK 3.0 removes measurements. This PR makes sure that we do not use `measurements` internally but rather use `span.data` instead. --------- Co-authored-by: Daniel Szoke <daniel.szoke@sentry.io>
1 parent d6fbe37 commit 6a1b263

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/sentry/utils/sdk.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import copy
44
import logging
55
import sys
6+
import typing
67
from collections.abc import Generator, Mapping, Sequence, Sized
78
from types import FrameType
89
from typing import TYPE_CHECKING, Any, NamedTuple
@@ -237,12 +238,15 @@ def before_send_transaction(event: Event, _: Hint) -> Event | None:
237238
num_of_spans = len(event["spans"])
238239

239240
event["tags"]["spans_over_limit"] = str(num_of_spans >= 1000)
240-
if not event["measurements"]:
241-
event["measurements"] = {}
242-
event["measurements"]["num_of_spans"] = {
243-
"value": num_of_spans,
244-
"unit": None,
245-
}
241+
242+
# Type safety: `event["contexts"]["trace"]["data"]` is a dictionary if it is set.
243+
# See https://develop.sentry.dev/sdk/data-model/event-payloads/contexts/#trace-context.
244+
data = typing.cast(
245+
dict[str, object],
246+
event.setdefault("contexts", {}).setdefault("trace", {}).setdefault("data", {}),
247+
)
248+
data["num_of_spans"] = num_of_spans
249+
246250
return event
247251

248252

@@ -695,15 +699,6 @@ def parse_org_slug(x: Organization | RpcOrganization | str) -> str:
695699
)
696700

697701

698-
def set_measurement(measurement_name, value, unit=None):
699-
try:
700-
transaction = sentry_sdk.Scope.get_current_scope().transaction
701-
if transaction is not None:
702-
transaction.set_measurement(measurement_name, value, unit)
703-
except Exception:
704-
pass
705-
706-
707702
def set_span_attribute(data_name, value):
708703
span = sentry_sdk.get_current_span()
709704
if span is not None:
@@ -746,6 +741,5 @@ def merge_context_into_scope(
746741
"patch_transport_for_instrumentation",
747742
"isolation_scope",
748743
"set_current_event_project",
749-
"set_measurement",
750744
"traces_sampler",
751745
)

0 commit comments

Comments
 (0)