File tree 2 files changed +21
-9
lines changed
2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -440,8 +440,9 @@ def start_span(
440
440
kwargs .setdefault ("hub" , self )
441
441
442
442
if span is None :
443
- if scope .span is not None :
444
- span = scope .span .new_span (** kwargs )
443
+ span = scope .span
444
+ if span is not None :
445
+ span = span .new_span (** kwargs )
445
446
else :
446
447
span = Span (** kwargs )
447
448
@@ -570,17 +571,19 @@ def iter_trace_propagation_headers(self):
570
571
# type: () -> Generator[Tuple[str, str], None, None]
571
572
# TODO: Document
572
573
client , scope = self ._stack [- 1 ]
573
- if scope ._span is None :
574
+ span = scope .span
575
+
576
+ if span is None :
574
577
return
575
578
576
579
propagate_traces = client and client .options ["propagate_traces" ]
577
580
if not propagate_traces :
578
581
return
579
582
580
583
if client and client .options ["traceparent_v2" ]:
581
- traceparent = scope . _span .to_traceparent ()
584
+ traceparent = span .to_traceparent ()
582
585
else :
583
- traceparent = scope . _span .to_legacy_traceparent ()
586
+ traceparent = span .to_legacy_traceparent ()
584
587
585
588
yield "sentry-trace" , traceparent
586
589
Original file line number Diff line number Diff line change @@ -66,6 +66,12 @@ class Scope(object):
66
66
events that belong to it.
67
67
"""
68
68
69
+ # NOTE: Even though it should not happen, the scope needs to not crash when
70
+ # accessed by multiple threads. It's fine if it's full of races, but those
71
+ # races should never make the user application crash.
72
+ #
73
+ # The same needs to hold for any accesses of the scope the SDK makes.
74
+
69
75
__slots__ = (
70
76
"_level" ,
71
77
"_name" ,
@@ -124,8 +130,9 @@ def transaction(self, value):
124
130
# type: (Optional[str]) -> None
125
131
"""When set this forces a specific transaction name to be set."""
126
132
self ._transaction = value
127
- if self ._span :
128
- self ._span .transaction = value
133
+ span = self ._span
134
+ if span :
135
+ span .transaction = value
129
136
130
137
@_attr_setter
131
138
def user (self , value ):
@@ -143,8 +150,10 @@ def span(self):
143
150
def span (self , span ):
144
151
# type: (Optional[Span]) -> None
145
152
self ._span = span
146
- if span is not None and span .transaction :
147
- self ._transaction = span .transaction
153
+ if span is not None :
154
+ span_transaction = span .transaction
155
+ if span_transaction :
156
+ self ._transaction = span_transaction
148
157
149
158
def set_tag (
150
159
self ,
You can’t perform that action at this time.
0 commit comments