Skip to content

Make UUID generation Lazy / Create PropagationContext class #2827

@antonpirker

Description

@antonpirker

We want to lazily create UUIDs to decrease the number of CPU cycles we use.

There are two important places where UUIDs are created:

  1. Span/Transaction creation: https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/tracing.py#L145-L146
  2. When a propagation context is created: https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/scope.py#L225-L232
  3. When creating a Profile: https://github.com/getsentry/sentry-python/blob/sentry-sdk-2.0/sentry_sdk/profiler.py#L455
  4. When creating a Session: https://github.com/getsentry/sentry-python/blob/sentry-sdk-2.0/sentry_sdk/session.py#L49

Solution brainstorm

  1. There is a PR that already started the work: Make UUID generation lazy #2826
    This already fixes point 1. from above.
  2. For point 2. we need to create a class PropagationContext and create the uuid4 only when the trace_id or the span_id is read.
  3. Implement similar to 1.
  4. Implement similar to 1.

Metadata

Metadata

Assignees

Labels

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions