@@ -696,19 +696,13 @@ def fingerprint(self, value):
696
696
def transaction (self ):
697
697
# type: () -> Any
698
698
# would be type: () -> Optional[Transaction], see https://github.com/python/mypy/issues/3004
699
- """Return the transaction (root span) in the scope, if any."""
700
-
701
- # there is no span/transaction on the scope
702
- if self ._span is None :
703
- return None
704
-
705
- # there is an orphan span on the scope
706
- if self ._span .containing_transaction is None :
707
- return None
699
+ """
700
+ Return the transaction (root span) in the scope, if any.
708
701
709
- # there is either a transaction (which is its own containing
710
- # transaction) or a non-orphan span on the scope
711
- return self ._span .containing_transaction
702
+ .. deprecated:: 3.0.0
703
+ This property is deprecated. Use root_span instead.
704
+ """
705
+ return self .root_span
712
706
713
707
@transaction .setter
714
708
def transaction (self , value ):
@@ -735,6 +729,22 @@ def transaction(self, value):
735
729
if self ._span and self ._span .containing_transaction :
736
730
self ._span .containing_transaction .name = value
737
731
732
+ @property
733
+ def root_span (self ):
734
+ # type: () -> POTelSpan
735
+ """Return the root span in the scope, if any."""
736
+
737
+ # there is no span on the scope
738
+ if self ._span is None :
739
+ return None
740
+
741
+ # this is a root span
742
+ if self ._span .root_span is None :
743
+ return self ._span
744
+
745
+ # get the topmost parent
746
+ return self ._span .root_span
747
+
738
748
def set_transaction_name (self , name , source = None ):
739
749
# type: (str, Optional[str]) -> None
740
750
"""Set the transaction name and optionally the transaction source."""
@@ -1014,25 +1024,24 @@ def start_span(self, span=None, custom_sampling_context=None, **kwargs):
1014
1024
1015
1025
For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Span`.
1016
1026
"""
1017
- with new_scope ():
1018
- kwargs .setdefault ("scope" , self )
1027
+ kwargs .setdefault ("scope" , self )
1019
1028
1020
- # get current span or transaction
1021
- span = span or self .span or self .get_isolation_scope ().span
1029
+ # get current span or transaction
1030
+ span = span or self .span or self .get_isolation_scope ().span
1022
1031
1023
- if span is None :
1024
- # New spans get the `trace_id` from the scope
1025
- if "trace_id" not in kwargs :
1026
- propagation_context = self .get_active_propagation_context ()
1027
- if propagation_context is not None :
1028
- kwargs ["trace_id" ] = propagation_context .trace_id
1032
+ if span is None :
1033
+ # New spans get the `trace_id` from the scope
1034
+ if "trace_id" not in kwargs :
1035
+ propagation_context = self .get_active_propagation_context ()
1036
+ if propagation_context is not None :
1037
+ kwargs ["trace_id" ] = propagation_context .trace_id
1029
1038
1030
- span = POTelSpan (** kwargs )
1031
- else :
1032
- # Children take `trace_id`` from the parent span.
1033
- span = span .start_child (** kwargs )
1039
+ span = POTelSpan (** kwargs )
1040
+ else :
1041
+ # Children take `trace_id`` from the parent span.
1042
+ span = span .start_child (** kwargs )
1034
1043
1035
- return span
1044
+ return span
1036
1045
1037
1046
def continue_trace (
1038
1047
self , environ_or_headers , op = None , name = None , source = None , origin = None
0 commit comments