Skip to content

Commit

Permalink
Making sure the tracing information lives on the current scope
Browse files Browse the repository at this point in the history
  • Loading branch information
antonpirker committed Feb 21, 2024
1 parent ba8cb07 commit e4febed
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def configure_scope( # noqa: F811
:returns: If no callback is provided, returns a context manager that returns the scope.
"""
scope = Scope.get_isolation_scope()
scope = Scope.get_current_scope()
scope.generate_propagation_context()

if callback is not None:
Expand Down Expand Up @@ -228,7 +228,7 @@ def __init__(self):

def __enter__(self):

Check warning on line 229 in sentry_sdk/api.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/api.py#L229

Added line #L229 was not covered by tests
# type: () -> Scope
return Scope.get_isolation_scope()
return Scope.get_current_scope()

Check warning on line 231 in sentry_sdk/api.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/api.py#L231

Added line #L231 was not covered by tests

def __exit__(self, exc_type, exc_value, tb):

Check warning on line 233 in sentry_sdk/api.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/api.py#L233

Added line #L233 was not covered by tests
# type: (Any, Any, Any) -> None
Expand Down Expand Up @@ -318,15 +318,15 @@ def get_traceparent():
"""
Returns the traceparent either from the active span or from the scope.
"""
return Scope.get_isolation_scope().get_traceparent()
return Scope.get_current_scope().get_traceparent()

Check warning on line 321 in sentry_sdk/api.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/api.py#L321

Added line #L321 was not covered by tests


def get_baggage():
# type: () -> Optional[str]
"""
Returns Baggage either from the active span or from the scope.
"""
baggage = Scope.get_isolation_scope().get_baggage()
baggage = Scope.get_current_scope().get_baggage()

Check warning on line 329 in sentry_sdk/api.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/api.py#L329

Added line #L329 was not covered by tests

if baggage is not None:
return baggage.serialize()

Check warning on line 332 in sentry_sdk/api.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/api.py#L332

Added line #L332 was not covered by tests
Expand All @@ -339,6 +339,6 @@ def continue_trace(environ_or_headers, op=None, name=None, source=None):
"""
Sets the propagation context from environment or headers and returns a transaction.
"""
return Scope.get_isolation_scope().continue_trace(
return Scope.get_current_scope().continue_trace(
environ_or_headers, op, name, source
)
2 changes: 1 addition & 1 deletion sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def scope(self):
This property is deprecated and will be removed in a future release.
Returns the current scope on the hub.
"""
return Scope.get_isolation_scope()
return Scope.get_current_scope()

def last_event_id(self):
# type: () -> Optional[str]
Expand Down
5 changes: 3 additions & 2 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ def set_new_propagation_context(self):
def generate_propagation_context(self, incoming_data=None):
# type: (Optional[Dict[str, str]]) -> None
"""
Makes sure `_propagation_context` is set.
Makes sure the propagation context (`_propagation_context`) is set.
The propagation context only lives on the current scope.
If there is `incoming_data` overwrite existing `_propagation_context`.
if there is no `incoming_data` create new `_propagation_context`, but do NOT overwrite if already existing.
"""
Expand All @@ -468,7 +469,7 @@ def generate_propagation_context(self, incoming_data=None):
self._propagation_context,
)

if self._propagation_context is None and self._type != ScopeType.CURRENT:
if self._propagation_context is None and self._type == ScopeType.CURRENT:
self.set_new_propagation_context()

def get_dynamic_sampling_context(self):
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def get_current_span(scope=None):
"""
Returns the currently active span if there is one running, otherwise `None`
"""
scope = scope or sentry_sdk.Scope.get_isolation_scope()
scope = scope or sentry_sdk.Scope.get_current_scope()
current_span = scope.span

Check warning on line 570 in sentry_sdk/tracing_utils.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/tracing_utils.py#L569-L570

Added lines #L569 - L570 were not covered by tests
return current_span

Expand Down

0 comments on commit e4febed

Please sign in to comment.