Skip to content
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

Make UUID generation lazy #2826

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 30 additions & 4 deletions sentry_sdk/tracing.py
Expand Up @@ -92,8 +92,8 @@
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 @@
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 @@
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