2525 NoOpSpan ,
2626 Span ,
2727 Transaction ,
28+ POTelSpan ,
2829)
2930from sentry_sdk ._types import TYPE_CHECKING
3031from sentry_sdk .utils import (
@@ -963,6 +964,10 @@ def start_transaction(
963964 ):
964965 # type: (Optional[Transaction], Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
965966 """
967+ .. deprecated:: 3.0.0
968+ This function is deprecated and will be removed in a future release.
969+ Use :py:meth:`sentry_sdk.start_span` instead.
970+
966971 Start and return a transaction.
967972
968973 Start an existing transaction if given, otherwise create and start a new
@@ -993,19 +998,12 @@ def start_transaction(
993998 """
994999 kwargs .setdefault ("scope" , self )
9951000
996- client = self .get_client ()
997-
9981001 try_autostart_continuous_profiler ()
9991002
10001003 custom_sampling_context = custom_sampling_context or {}
10011004
1002- # kwargs at this point has type TransactionKwargs, since we have removed
1003- # the client and custom_sampling_context from it.
1004- transaction_kwargs = kwargs # type: TransactionKwargs
1005-
10061005 # if we haven't been given a transaction, make one
1007- if transaction is None :
1008- transaction = Transaction (** transaction_kwargs )
1006+ transaction = transaction or POTelSpan (** kwargs )
10091007
10101008 # use traces_sample_rate, traces_sampler, and/or inheritance to make a
10111009 # sampling decision
@@ -1024,39 +1022,24 @@ def start_transaction(
10241022
10251023 transaction ._profile = profile
10261024
1027- # we don't bother to keep spans if we already know we're not going to
1028- # send the transaction
1029- max_spans = (client .options ["_experiments" ].get ("max_spans" )) or 1000
1030- transaction .init_span_recorder (maxlen = max_spans )
1031-
10321025 return transaction
10331026
1034- def start_span (self , ** kwargs ):
1035- # type: (Any) -> Span
1027+ def start_span (self , span = None , custom_sampling_context = None , ** kwargs ):
1028+ # type: (Optional[Span], Optional[SamplingContext], Any) -> Span
10361029 """
1037- Start a span whose parent is the currently active span or transaction , if any.
1030+ Start a span whose parent is the currently active span, if any.
10381031
10391032 The return value is a :py:class:`sentry_sdk.tracing.Span` instance,
10401033 typically used as a context manager to start and stop timing in a `with`
10411034 block.
10421035
1043- Only spans contained in a transaction are sent to Sentry. Most
1044- integrations start a transaction at the appropriate time, for example
1045- for every incoming HTTP request. Use
1046- :py:meth:`sentry_sdk.start_transaction` to start a new transaction when
1047- one is not already in progress.
1048-
10491036 For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Span`.
1050-
1051- The instrumenter parameter is deprecated for user code, and it will
1052- be removed in the next major version. Going forward, it should only
1053- be used by the SDK itself.
10541037 """
10551038 with new_scope ():
10561039 kwargs .setdefault ("scope" , self )
10571040
10581041 # get current span or transaction
1059- span = self .span or self .get_isolation_scope ().span
1042+ span = span or self .span or self .get_isolation_scope ().span
10601043
10611044 if span is None :
10621045 # New spans get the `trace_id` from the scope
@@ -1065,7 +1048,7 @@ def start_span(self, **kwargs):
10651048 if propagation_context is not None :
10661049 kwargs ["trace_id" ] = propagation_context .trace_id
10671050
1068- span = Span (** kwargs )
1051+ span = POTelSpan (** kwargs )
10691052 else :
10701053 # Children take `trace_id`` from the parent span.
10711054 span = span .start_child (** kwargs )
0 commit comments