Skip to content

Commit

Permalink
Make UUID generation lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Mar 15, 2024
1 parent 16d25e2 commit 64e0ec5
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions sentry_sdk/tracing.py
Expand Up @@ -92,8 +92,8 @@ class Span(object):
Spans can have multiple child spans thus forming a span tree."""

__slots__ = (
"trace_id",
"span_id",
"_trace_id",
"_span_id",
"parent_span_id",
"same_process_as_parent",
"sampled",
Expand Down Expand Up @@ -142,8 +142,8 @@ def __init__(
start_timestamp=None, # type: Optional[Union[datetime, float]]
):
# type: (...) -> None
self.trace_id = trace_id or uuid.uuid4().hex
self.span_id = span_id or uuid.uuid4().hex[16:]
self._trace_id = trace_id
self._span_id = span_id
self.parent_span_id = parent_span_id
self.same_process_as_parent = same_process_as_parent
self.sampled = sampled
Expand Down Expand Up @@ -179,6 +179,32 @@ def init_span_recorder(self, maxlen):
if self._span_recorder is None:
self._span_recorder = _SpanRecorder(maxlen)

@property
def trace_id(self):
# type: () -> str
if not self._trace_id:
self._trace_id = uuid.uuid4().hex

return self._trace_id

@trace_id.setter
def trace_id(self, value):
# type: (str) -> None
self._trace_id = value

Check warning on line 193 in sentry_sdk/tracing.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/tracing.py#L193

Added line #L193 was not covered by tests

@property
def span_id(self):
# type: () -> str
if not self._span_id:
self._span_id = uuid.uuid4().hex[16:]

return self._span_id

@span_id.setter
def span_id(self, value):
# type: (str) -> None
self._span_id = value

Check warning on line 206 in sentry_sdk/tracing.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/tracing.py#L206

Added line #L206 was not covered by tests

def _get_local_aggregator(self):
# type: (...) -> LocalAggregator
rv = self._local_aggregator
Expand Down

0 comments on commit 64e0ec5

Please sign in to comment.