25
25
NoOpSpan ,
26
26
Span ,
27
27
Transaction ,
28
- POTelSpan ,
29
28
)
30
29
from sentry_sdk .utils import (
31
30
capture_internal_exception ,
@@ -696,13 +695,18 @@ def fingerprint(self, value):
696
695
def transaction (self ):
697
696
# type: () -> Any
698
697
# 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."""
701
699
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
706
710
707
711
@transaction .setter
708
712
def transaction (self , value ):
@@ -729,22 +733,6 @@ def transaction(self, value):
729
733
if self ._span and self ._span .containing_transaction :
730
734
self ._span .containing_transaction .name = value
731
735
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
-
748
736
def set_transaction_name (self , name , source = None ):
749
737
# type: (str, Optional[str]) -> None
750
738
"""Set the transaction name and optionally the transaction source."""
@@ -953,10 +941,6 @@ def start_transaction(
953
941
):
954
942
# type: (Optional[Transaction], Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
955
943
"""
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
-
960
944
Start and return a transaction.
961
945
962
946
Start an existing transaction if given, otherwise create and start a new
@@ -987,12 +971,14 @@ def start_transaction(
987
971
"""
988
972
kwargs .setdefault ("scope" , self )
989
973
974
+ client = self .get_client ()
975
+
990
976
try_autostart_continuous_profiler ()
991
977
992
978
custom_sampling_context = custom_sampling_context or {}
993
979
994
980
# if we haven't been given a transaction, make one
995
- transaction = transaction or POTelSpan (** kwargs )
981
+ transaction = Transaction (** kwargs )
996
982
997
983
# use traces_sample_rate, traces_sampler, and/or inheritance to make a
998
984
# sampling decision
@@ -1011,10 +997,15 @@ def start_transaction(
1011
997
1012
998
transaction ._profile = profile
1013
999
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
+
1014
1005
return transaction
1015
1006
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
1018
1009
"""
1019
1010
Start a span whose parent is the currently active span, if any.
1020
1011
@@ -1024,24 +1015,25 @@ def start_span(self, span=None, custom_sampling_context=None, **kwargs):
1024
1015
1025
1016
For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Span`.
1026
1017
"""
1027
- kwargs .setdefault ("scope" , self )
1018
+ with new_scope ():
1019
+ kwargs .setdefault ("scope" , self )
1028
1020
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
1031
1023
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
1038
1030
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 )
1043
1035
1044
- return span
1036
+ return span
1045
1037
1046
1038
def continue_trace (
1047
1039
self , environ_or_headers , op = None , name = None , source = None , origin = None
0 commit comments