Skip to content

Commit 7f09094

Browse files
authored
perf(traces): Cache valid span statuses in a module-level frozenset (#6208)
The `status` setter on `StreamedSpan` was reconstructing a set from the `SpanStatus` enum on every invocation. In high-throughput tracing workloads this is a hot path, so caching the values in a module-level `frozenset` avoids repeated allocations. Fixes #6207 Fixes PY-2403
1 parent d40313b commit 7f09094

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

sentry_sdk/traces.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def __str__(self) -> str:
6060
return self.value
6161

6262

63+
_VALID_SPAN_STATUSES = frozenset(e.value for e in SpanStatus)
64+
65+
6366
# Segment source, see
6467
# https://getsentry.github.io/sentry-conventions/generated/attributes/sentry.html#sentryspansource
6568
class SegmentSource(str, Enum):
@@ -430,7 +433,7 @@ def status(self, status: "Union[SpanStatus, str]") -> None:
430433
if isinstance(status, Enum):
431434
status = status.value
432435

433-
if status not in {e.value for e in SpanStatus}:
436+
if status not in _VALID_SPAN_STATUSES:
434437
logger.debug(
435438
f'[Tracing] Unsupported span status {status}. Expected one of: "ok", "error"'
436439
)

0 commit comments

Comments
 (0)