File tree Expand file tree Collapse file tree 12 files changed +39
-25
lines changed
Filter options
Expand file tree Collapse file tree 12 files changed +39
-25
lines changed
Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
162
162
- ` same_process_as_parent `
163
163
- ` span_id `
164
164
- ` parent_span_id ` : you can supply a ` parent_span ` instead
165
- - Setting ` Scope.transaction ` directly is no longer supported. Use ` Scope.set_transaction_name() ` instead .
165
+ - The ` Scope.transaction ` property has been removed. To obtain the root span, use ` Scope.root_span ` . To set the root span's name, use ` Scope.set_transaction_name() ` .
166
166
- Passing a list or ` None ` for ` failed_request_status_codes ` in the Starlette integration is no longer supported. Pass a set of integers instead.
167
167
- The ` span ` argument of ` Scope.trace_propagation_meta ` is no longer supported.
168
168
- Setting ` Scope.user ` directly is no longer supported. Use ` Scope.set_user() ` instead.
Original file line number Diff line number Diff line change @@ -299,7 +299,7 @@ def start_transaction(
299
299
300
300
def set_measurement (name , value , unit = "" ):
301
301
# type: (str, float, MeasurementUnit) -> None
302
- transaction = get_current_scope ().transaction
302
+ transaction = get_current_scope ().root_span
303
303
if transaction is not None :
304
304
transaction .set_measurement (name , value , unit )
305
305
Original file line number Diff line number Diff line change @@ -850,7 +850,7 @@ def _capture_experimental_log(self, current_scope, log):
850
850
log ["attributes" ]["sentry.trace.parent_span_id" ] = span .span_id
851
851
852
852
if log .get ("trace_id" ) is None :
853
- transaction = current_scope .transaction
853
+ transaction = current_scope .root_span
854
854
propagation_context = isolation_scope .get_active_propagation_context ()
855
855
if transaction is not None :
856
856
log ["trace_id" ] = transaction .trace_id
Original file line number Diff line number Diff line change @@ -127,12 +127,12 @@ def _capture_exception(exc_info):
127
127
# type: (ExcInfo) -> None
128
128
scope = sentry_sdk .get_current_scope ()
129
129
130
- if scope .transaction is not None :
130
+ if scope .root_span is not None :
131
131
if exc_info [0 ] in ARQ_CONTROL_FLOW_EXCEPTIONS :
132
- scope .transaction .set_status (SPANSTATUS .ABORTED )
132
+ scope .root_span .set_status (SPANSTATUS .ABORTED )
133
133
return
134
134
135
- scope .transaction .set_status (SPANSTATUS .INTERNAL_ERROR )
135
+ scope .root_span .set_status (SPANSTATUS .INTERNAL_ERROR )
136
136
137
137
event , hint = event_from_exception (
138
138
exc_info ,
@@ -149,8 +149,8 @@ def event_processor(event, hint):
149
149
150
150
with capture_internal_exceptions ():
151
151
scope = sentry_sdk .get_current_scope ()
152
- if scope .transaction is not None :
153
- scope .transaction .name = ctx ["job_name" ]
152
+ if scope .root_span is not None :
153
+ scope .root_span .name = ctx ["job_name" ]
154
154
event ["transaction" ] = ctx ["job_name" ]
155
155
156
156
tags = event .setdefault ("tags" , {})
Original file line number Diff line number Diff line change @@ -176,8 +176,8 @@ def wrap_async_view(callback):
176
176
async def sentry_wrapped_callback (request , * args , ** kwargs ):
177
177
# type: (Any, *Any, **Any) -> Any
178
178
current_scope = sentry_sdk .get_current_scope ()
179
- if current_scope .transaction is not None :
180
- current_scope .transaction .update_active_thread ()
179
+ if current_scope .root_span is not None :
180
+ current_scope .root_span .update_active_thread ()
181
181
182
182
sentry_scope = sentry_sdk .get_isolation_scope ()
183
183
if sentry_scope .profile is not None :
Original file line number Diff line number Diff line change @@ -79,8 +79,8 @@ def _wrap_sync_view(callback):
79
79
def sentry_wrapped_callback (request , * args , ** kwargs ):
80
80
# type: (Any, *Any, **Any) -> Any
81
81
current_scope = sentry_sdk .get_current_scope ()
82
- if current_scope .transaction is not None :
83
- current_scope .transaction .update_active_thread ()
82
+ if current_scope .root_span is not None :
83
+ current_scope .root_span .update_active_thread ()
84
84
85
85
sentry_scope = sentry_sdk .get_isolation_scope ()
86
86
# set the active thread id to the handler thread for sync views
Original file line number Diff line number Diff line change @@ -89,8 +89,8 @@ def _sentry_get_request_handler(*args, **kwargs):
89
89
def _sentry_call (* args , ** kwargs ):
90
90
# type: (*Any, **Any) -> Any
91
91
current_scope = sentry_sdk .get_current_scope ()
92
- if current_scope .transaction is not None :
93
- current_scope .transaction .update_active_thread ()
92
+ if current_scope .root_span is not None :
93
+ current_scope .root_span .update_active_thread ()
94
94
95
95
sentry_scope = sentry_sdk .get_isolation_scope ()
96
96
if sentry_scope .profile is not None :
Original file line number Diff line number Diff line change @@ -111,10 +111,10 @@ def _capture_exception(exc_info):
111
111
scope = sentry_sdk .get_current_scope ()
112
112
113
113
if exc_info [0 ] in HUEY_CONTROL_FLOW_EXCEPTIONS :
114
- scope .transaction .set_status (SPANSTATUS .ABORTED )
114
+ scope .root_span .set_status (SPANSTATUS .ABORTED )
115
115
return
116
116
117
- scope .transaction .set_status (SPANSTATUS .INTERNAL_ERROR )
117
+ scope .root_span .set_status (SPANSTATUS .INTERNAL_ERROR )
118
118
event , hint = event_from_exception (
119
119
exc_info ,
120
120
client_options = sentry_sdk .get_client ().options ,
@@ -136,7 +136,7 @@ def _sentry_execute(*args, **kwargs):
136
136
_capture_exception (exc_info )
137
137
reraise (* exc_info )
138
138
else :
139
- sentry_sdk .get_current_scope ().transaction .set_status (SPANSTATUS .OK )
139
+ sentry_sdk .get_current_scope ().root_span .set_status (SPANSTATUS .OK )
140
140
141
141
return result
142
142
Original file line number Diff line number Diff line change @@ -122,8 +122,8 @@ def decorator(old_func):
122
122
def _sentry_func (* args , ** kwargs ):
123
123
# type: (*Any, **Any) -> Any
124
124
current_scope = sentry_sdk .get_current_scope ()
125
- if current_scope .transaction is not None :
126
- current_scope .transaction .update_active_thread ()
125
+ if current_scope .root_span is not None :
126
+ current_scope .root_span .update_active_thread ()
127
127
128
128
sentry_scope = sentry_sdk .get_isolation_scope ()
129
129
if sentry_scope .profile is not None :
Original file line number Diff line number Diff line change @@ -477,8 +477,8 @@ def _sentry_sync_func(*args, **kwargs):
477
477
return old_func (* args , ** kwargs )
478
478
479
479
current_scope = sentry_sdk .get_current_scope ()
480
- if current_scope .transaction is not None :
481
- current_scope .transaction .update_active_thread ()
480
+ if current_scope .root_span is not None :
481
+ current_scope .root_span .update_active_thread ()
482
482
483
483
sentry_scope = sentry_sdk .get_isolation_scope ()
484
484
if sentry_scope .profile is not None :
Original file line number Diff line number Diff line change @@ -688,10 +688,9 @@ def fingerprint(self, value):
688
688
self ._fingerprint = value
689
689
690
690
@property
691
- def transaction (self ):
692
- # type: () -> Any
693
- # would be type: () -> Optional[Span], see https://github.com/python/mypy/issues/3004
694
- """Return the transaction (root span) in the scope, if any."""
691
+ def root_span (self ):
692
+ # type: () -> Optional[Span]
693
+ """Return the root span in the scope, if any."""
695
694
696
695
# there is no span/transaction on the scope
697
696
if self ._span is None :
Original file line number Diff line number Diff line change @@ -915,3 +915,18 @@ def test_last_event_id_cleared(sentry_init):
915
915
Scope .get_isolation_scope ().clear ()
916
916
917
917
assert Scope .last_event_id () is None , "last_event_id should be cleared"
918
+
919
+
920
+ def test_root_span (sentry_init ):
921
+ sentry_init (traces_sample_rate = 1.0 )
922
+
923
+ assert sentry_sdk .get_current_scope ().root_span is None
924
+
925
+ with sentry_sdk .start_span (name = "test" ) as root_span :
926
+ assert sentry_sdk .get_current_scope ().root_span == root_span
927
+ with sentry_sdk .start_span (name = "child" ):
928
+ assert sentry_sdk .get_current_scope ().root_span == root_span
929
+ with sentry_sdk .start_span (name = "grandchild" ):
930
+ assert sentry_sdk .get_current_scope ().root_span == root_span
931
+
932
+ assert sentry_sdk .get_current_scope ().root_span is None
You can’t perform that action at this time.
0 commit comments