Skip to content

Commit 822ad0f

Browse files
committed
Make types consistent with relay changes
1 parent 9dd1a48 commit 822ad0f

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

sentry_sdk/_types.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,34 @@
4848
]
4949
SessionStatus = Literal["ok", "exited", "crashed", "abnormal"]
5050
EndpointType = Literal["store", "envelope"]
51-
MeasurementUnit = Literal["ns", "ms", "s"]
51+
52+
DurationUnit = Literal[
53+
"nanosecond",
54+
"microsecond",
55+
"millisecond",
56+
"second",
57+
"minute",
58+
"hour",
59+
"day",
60+
"week",
61+
]
62+
63+
InformationUnit = Literal[
64+
"bit",
65+
"byte",
66+
"kilobyte",
67+
"kibibyte",
68+
"megabyte",
69+
"mebibyte",
70+
"gigabyte",
71+
"gibibyte",
72+
"terabyte",
73+
"tebibyte",
74+
"petabyte",
75+
"pebibyte",
76+
"exabyte",
77+
"exbibyte",
78+
]
79+
80+
FractionUnit = Literal["ratio", "percent"]
81+
MeasurementUnit = Union[DurationUnit, InformationUnit, FractionUnit, str]

sentry_sdk/tracing.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,18 +605,14 @@ def finish(self, hub=None):
605605

606606
return hub.capture_event(event)
607607

608-
def set_measurement(self, name, value, unit="ms"):
608+
def set_measurement(self, name, value, unit=""):
609609
# type: (str, float, MeasurementUnit) -> None
610610
if not has_custom_measurements_enabled():
611611
logger.debug(
612612
"[Tracing] Experimental custom_measurements feature is disabled"
613613
)
614614
return
615615

616-
if unit not in ("ns", "ms", "s"):
617-
logger.debug("[Tracing] Discarding measurement due to invalid unit")
618-
return
619-
620616
self._measurements[name] = {"value": value, "unit": unit}
621617

622618
def to_json(self):

tests/tracing/test_misc.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,11 @@ def test_set_meaurement(sentry_init, capture_events):
255255

256256
transaction = start_transaction(name="measuring stuff")
257257
transaction.set_measurement("metric.foo", 123)
258-
transaction.set_measurement("metric.bar", 456, unit="s")
258+
transaction.set_measurement("metric.bar", 456, unit="second")
259+
transaction.set_measurement("metric.baz", 420.69, unit="custom")
259260
transaction.finish()
260261

261262
(event,) = events
262-
assert event["measurements"]["metric.foo"] == {"value": 123, "unit": "ms"}
263-
assert event["measurements"]["metric.bar"] == {"value": 456, "unit": "s"}
263+
assert event["measurements"]["metric.foo"] == {"value": 123, "unit": ""}
264+
assert event["measurements"]["metric.bar"] == {"value": 456, "unit": "second"}
265+
assert event["measurements"]["metric.baz"] == {"value": 420.69, "unit": "custom"}

0 commit comments

Comments
 (0)