2525 NoOpSpan ,
2626 Span ,
2727 Transaction ,
28- POTelSpan ,
2928)
3029from sentry_sdk .utils import (
3130 capture_internal_exception ,
@@ -696,13 +695,18 @@ def fingerprint(self, value):
696695 def transaction (self ):
697696 # type: () -> Any
698697 # would be type: () -> Optional[Transaction], see https://github.com/python/mypy/issues/3004
699- """
700- Return the transaction (root span) in the scope, if any.
698+ """Return the transaction (root span) in the scope, if any."""
701699
702- .. deprecated:: 3.0.0
703- This property is deprecated. Use root_span instead.
704- """
705- return self .root_span
700+ # there is no span/transaction on the scope
701+ if self ._span is None :
702+ return None
703+
704+ # there is an orphan span on the scope
705+ if self ._span .containing_transaction is None :
706+ return None
707+ # there is either a transaction (which is its own containing
708+ # transaction) or a non-orphan span on the scope
709+ return self ._span .containing_transaction
706710
707711 @transaction .setter
708712 def transaction (self , value ):
@@ -729,22 +733,6 @@ def transaction(self, value):
729733 if self ._span and self ._span .containing_transaction :
730734 self ._span .containing_transaction .name = value
731735
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-
748736 def set_transaction_name (self , name , source = None ):
749737 # type: (str, Optional[str]) -> None
750738 """Set the transaction name and optionally the transaction source."""
@@ -953,10 +941,6 @@ def start_transaction(
953941 ):
954942 # type: (Optional[Transaction], Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
955943 """
956- .. deprecated:: 3.0.0
957- This function is deprecated and will be removed in a future release.
958- Use :py:meth:`sentry_sdk.start_span` instead.
959-
960944 Start and return a transaction.
961945
962946 Start an existing transaction if given, otherwise create and start a new
@@ -987,12 +971,14 @@ def start_transaction(
987971 """
988972 kwargs .setdefault ("scope" , self )
989973
974+ client = self .get_client ()
975+
990976 try_autostart_continuous_profiler ()
991977
992978 custom_sampling_context = custom_sampling_context or {}
993979
994980 # if we haven't been given a transaction, make one
995- transaction = transaction or POTelSpan (** kwargs )
981+ transaction = Transaction (** kwargs )
996982
997983 # use traces_sample_rate, traces_sampler, and/or inheritance to make a
998984 # sampling decision
@@ -1011,10 +997,15 @@ def start_transaction(
1011997
1012998 transaction ._profile = profile
1013999
1000+ # we don't bother to keep spans if we already know we're not going to
1001+ # send the transaction
1002+ max_spans = (client .options ["_experiments" ].get ("max_spans" )) or 1000
1003+ transaction .init_span_recorder (maxlen = max_spans )
1004+
10141005 return transaction
10151006
1016- def start_span (self , span = None , custom_sampling_context = None , ** kwargs ):
1017- # type: (Optional[Span], Optional[SamplingContext], Any) -> Span
1007+ def start_span (self , ** kwargs ):
1008+ # type: (Optional[Span], Any) -> Span
10181009 """
10191010 Start a span whose parent is the currently active span, if any.
10201011
@@ -1024,24 +1015,25 @@ def start_span(self, span=None, custom_sampling_context=None, **kwargs):
10241015
10251016 For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Span`.
10261017 """
1027- kwargs .setdefault ("scope" , self )
1018+ with new_scope ():
1019+ kwargs .setdefault ("scope" , self )
10281020
1029- # get current span or transaction
1030- span = span or self .span or self .get_isolation_scope ().span
1021+ # get current span or transaction
1022+ span = self .span or self .get_isolation_scope ().span
10311023
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
1024+ if span is None :
1025+ # New spans get the `trace_id` from the scope
1026+ if "trace_id" not in kwargs :
1027+ propagation_context = self .get_active_propagation_context ()
1028+ if propagation_context is not None :
1029+ kwargs ["trace_id" ] = propagation_context .trace_id
10381030
1039- span = POTelSpan (** kwargs )
1040- else :
1041- # Children take `trace_id`` from the parent span.
1042- span = span .start_child (** kwargs )
1031+ span = Span (** kwargs )
1032+ else :
1033+ # Children take `trace_id`` from the parent span.
1034+ span = span .start_child (** kwargs )
10431035
1044- return span
1036+ return span
10451037
10461038 def continue_trace (
10471039 self , environ_or_headers , op = None , name = None , source = None , origin = None
0 commit comments