o
    BDi                  
   @   s  d dl mZ d dlZd dlZd dlmZmZmZ d dlmZ d dl	Z	d dl
mZmZmZ d dlmZ d dlmZmZmZmZmZ d dlmZ erd d	lmZmZmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlm Z  d dlm!Z! d dlm"Z" d dlm#Z# d dlm$Z$ d dlm%Z% d dl&m'Z'm(Z( e"dZ)e%dZ*d dlm+Z+ d dl,m-Z- d dl.m/Z/m0Z0m1Z1m2Z2 G dd de'ddZ3G dd de3ddZ4e'd d!e5iZ6d"Z7d#Z8G d$d% d%e5eZ9e9j:gZ;e9j<e9j<e9j<e9j=e9j:e9j<e9j=e9j=e9j=d&	Z>d'd( Z?G d)d* d*Z@G d+d, d,ZAG d-d. d.eAZBG d/d0 d0eAZCer)e!d8d1d2ZDe!d3d2 ZDd8d4d2ZDd d5lEmFZFmGZGmHZHmIZImJZJmKZK eL  eMd6eN d d7lOmPZP W d   dS 1 s[w   Y  dS )9    )DecimalN)datetime	timedeltatimezone)Enum)INSTRUMENTER
SPANSTATUSSPANDATA)get_profiler_id)get_current_thread_metais_valid_sample_rateloggernanosecond_timeshould_be_treated_as_error)TYPE_CHECKING)CallableMappingMutableMapping)Any)Dict)Iterator)List)Optional)overload)	ParamSpec)Tuple)Union)TypeVar)	TypedDictUnpackPR)ContinuousProfile)Profile)EventMeasurementUnitSamplingContextMeasurementValuec                   @   s   e Zd ZU eed< 	 eed< 	 eed< 	 eed< 	 eed< 	 eed< 	 eed< 	 ed ed	< 	 eed
< 	 ed ed< 	 eeee	f  ed< 	 ded< 	 eed< 	 eed< dS )
SpanKwargstrace_idspan_idparent_span_idsame_process_as_parentsampledopdescriptionzsentry_sdk.HubhubstatusTransactioncontaining_transactionstart_timestampzsentry_sdk.ScopescopeoriginnameN)
__name__
__module____qualname__str__annotations__boolr   r   r   float r?   r?   K/var/www/Datamplify/venv/lib/python3.10/site-packages/sentry_sdk/tracing.pyr(   0   s:   
 r(   F)totalc                   @   s*   e Zd ZU eed< 	 eed< 	 ded< dS )TransactionKwargssourceparent_sampledBaggagebaggageN)r8   r9   r:   r;   r<   r=   r?   r?   r?   r@   rB   k   s   
 rB   ProfileContextprofiler_idrF   zsentry-tracec                   @   s,   e Zd ZdZdZdZdZdZdZdd Z	d	S )
TransactionSource	componentcustomroutetaskurlviewc                 C      | j S N)valueselfr?   r?   r@   __str__      zTransactionSource.__str__N)
r8   r9   r:   	COMPONENTCUSTOMROUTETASKURLVIEWrU   r?   r?   r?   r@   rI      s    rI   )	endpointfunction_namehandler_namemethod_and_path_patternpath
route_nameroute_patternuri_templaterN   c                 C   s   | dk rt jS d|   krdk r@n n-| dkrt jS | dkr!t jS | dkr(t jS | dkr/t jS | dkr6t jS | dkr=t jS t jS d|   krJd	k rfn t jS | d
krUt j	S | dkr\t j
S | dkrct jS t jS t jS )z
    Returns the Sentry status corresponding to the given HTTP status code.

    See: https://develop.sentry.dev/sdk/event-payloads/contexts/#trace-context
    i  i  i  i  i  i  i  i  iX  i  i  i  )r   OKPERMISSION_DENIED	NOT_FOUNDRESOURCE_EXHAUSTEDFAILED_PRECONDITIONUNAUTHENTICATEDALREADY_EXISTSINVALID_ARGUMENTDEADLINE_EXCEEDEDUNIMPLEMENTEDUNAVAILABLEINTERNAL_ERRORUNKNOWN_ERROR)http_status_coder?   r?   r@   get_span_status_from_http_code   s4   
rs   c                   @   s$   e Zd ZdZdZdd Zdd ZdS )_SpanRecorderz5Limits the number of spans recorded in a transaction.maxlenspansdropped_spansc                 C   s   |d | _ g | _d| _d S )N   r   ru   rT   rv   r?   r?   r@   __init__   s   

z_SpanRecorder.__init__c                 C   s8   t | j| jkrd |_|  jd7  _d S | j| d S )Nry   )lenrw   rv   _span_recorderrx   append)rT   spanr?   r?   r@   add   s   z_SpanRecorder.addN)r8   r9   r:   __doc__	__slots__r{   r   r?   r?   r?   r@   rt      s
    rt   c                   @   s2  e Zd ZdZdZ														d@ddZdd	 Zd
d Zdd Zdd Z	dd Z
edd ZejfddZedd ZeddddZdd Zedd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* ZdAd,d-Zd.d/ Zd0d1 Zd2d3 Zd4d5 ZdBd6d7Z d8d9 Z!d:d; Z"d<d= Z#d>d? Z$dS )CSpanak  A span holds timing information of a block of code.
    Spans can have multiple child spans thus forming a span tree.

    :param trace_id: The trace ID of the root span. If this new span is to be the root span,
        omit this parameter, and a new trace ID will be generated.
    :param span_id: The span ID of this span. If omitted, a new span ID will be generated.
    :param parent_span_id: The span ID of the parent span, if applicable.
    :param same_process_as_parent: Whether this span is in the same process as the parent span.
    :param sampled: Whether the span should be sampled. Overrides the default sampling decision
        for this span when provided.
    :param op: The span's operation. A list of recommended values is available here:
        https://develop.sentry.dev/sdk/performance/span-operations/
    :param description: A description of what operation is being performed within the span.

        .. deprecated:: 2.15.0
            Please use the `name` parameter, instead.
    :param name: A string describing what operation is being performed within the span.
    :param hub: The hub to use for this span.

        .. deprecated:: 2.0.0
            Please use the `scope` parameter, instead.
    :param status: The span's status. Possible values are listed at
        https://develop.sentry.dev/sdk/event-payloads/span/
    :param containing_transaction: The transaction that this span belongs to.
    :param start_timestamp: The timestamp when the span started. If omitted, the current time
        will be used.
    :param scope: The scope to use for this span. If not provided, we use the current scope.
    )r)   r*   r+   r,   r-   r.   r/   _measurementsr4   _start_timestamp_monotonic_nsr1   	timestamp_tags_datar}   r0   _context_manager_state_containing_transaction_local_aggregatorr5   r6   r7   _flags_flags_capacityNTmanualc                 C   s*  |pt  j| _|pt  jdd  | _|| _|| _|| _|| _|p#|| _	|	| _
|| _|| _|| _i | _i | _i | _|
| _i | _d| _|d urVtjdtdd | jpT|j| _|d u rattj}nt|trmt|tj}|| _zt | _ W n	 t!y   Y nw d | _"d | _#d | _$| %  | &t'  d S )N   
   z>The `hub` parameter is deprecated. Please use `scope` instead.   
stacklevel)(uuiduuid4hexr)   r*   r+   r,   r-   r.   r/   r1   r0   r5   r6   r   r   r   r   r   r   warningswarnDeprecationWarningr   nowr   utc
isinstancer>   fromtimestampr4   r   r   AttributeErrorr   r}   r   update_active_threadset_profiler_idr
   )rT   r)   r*   r+   r,   r-   r.   r/   r0   r1   r3   r4   r5   r6   r7   r?   r?   r@   r{     sN   

zSpan.__init__c                 C   s   | j d u rt|| _ d S d S rQ   )r}   rt   rz   r?   r?   r@   init_span_recorderb  s   
zSpan.init_span_recorderc                 C   s   | j }|d u rt  }| _ |S rQ   )r   LocalAggregatorrT   rvr?   r?   r@   _get_local_aggregatorg  s   zSpan._get_local_aggregatorc              	   C   s*   d| j j| j| j| j| j| j| j| jf S )Nz^<%s(op=%r, description:%r, trace_id=%r, span_id=%r, parent_span_id=%r, sampled=%r, origin=%r)>)		__class__r8   r.   r/   r)   r*   r+   r-   r6   rS   r?   r?   r@   __repr__n  s   zSpan.__repr__c                 C   s(   | j pt }|j}| |_||f| _| S rQ   )r5   
sentry_sdkget_current_scoper   r   )rT   r5   old_spanr?   r?   r@   	__enter__~  s
   
zSpan.__enter__c                 C   s@   |d urt ||r| tj | j\}}| `| | ||_d S rQ   )r   
set_statusr   rp   r   finishr   )rT   tyrR   tbr5   r   r?   r?   r@   __exit__  s   


zSpan.__exit__c                 C   rP   )zThe ``Transaction`` that this span belongs to.
        The ``Transaction`` is the root of the span tree,
        so one could also think of this ``Transaction`` as the "root span".)r   rS   r?   r?   r@   r3     s   
zSpan.containing_transactionc                 K   s   | ddurtjdtdd t jd }||krt S |d| j	 t
d	| j| j| jd|}| jo8| jj}|r@|| |S )
a  
        Start a sub-span from the current span or transaction.

        Takes the same arguments as the initializer of :py:class:`Span`. The
        trace id, sampling decision, transaction pointer, and span recorder are
        inherited from the current span/transaction.

        The instrumenter parameter is deprecated for user code, and it will
        be removed in the next major version. Going forward, it should only
        be used by the SDK itself.
        r/   NzEThe `description` parameter is deprecated. Please use `name` instead.r   r   instrumenterr-   )r)   r+   r3   r?   )getr   r   r   r   
get_clientoptionsNoOpSpan
setdefaultr-   r   r)   r*   r3   r}   r   )rT   r   kwargsconfiguration_instrumenterchildspan_recorderr?   r?   r@   start_child  s,   
zSpan.start_childc                 K   s(   | t u r	td tjt|fi |S )a(  
        Create a Transaction with the given params, then add in data pulled from
        the ``sentry-trace`` and ``baggage`` headers from the environ (if any)
        before returning the Transaction.

        This is different from :py:meth:`~sentry_sdk.tracing.Span.continue_from_headers`
        in that it assumes header names in the form ``HTTP_HEADER_NAME`` -
        such as you would get from a WSGI/ASGI environ -
        rather than the form ``header-name``.

        :param environ: The ASGI/WSGI environ to pull information from.
        zXDeprecated: use Transaction.continue_from_environ instead of Span.continue_from_environ.)r   r   warningr2   continue_from_headersEnvironHeaders)clsenvironr   r?   r?   r@   continue_from_environ  s
   zSpan.continue_from_environ_sample_randc                K   st   | t u r	td tj|t|d}|t|i t|t	}|dur.|| |
  tdi |}d|_|S )a  
        Create a transaction with the given params (including any data pulled from
        the ``sentry-trace`` and ``baggage`` headers).

        :param headers: The dictionary with the HTTP headers to pull information from.
        :param _sample_rand: If provided, we override the sample_rand value from the
            incoming headers with this value. (internal use only)
        zXDeprecated: use Transaction.continue_from_headers instead of Span.continue_from_headers.r   NFr?   )r   r   r   rE   from_incoming_headerr   BAGGAGE_HEADER_NAMEupdateextract_sentrytrace_dataSENTRY_TRACE_HEADER_NAMEfreezer2   r,   )r   headersr   r   rF   sentrytrace_kwargstransactionr?   r?   r@   r     s"   

zSpan.continue_from_headersc                 c   s>    | j sdS t|  fV  | j   }|rt|fV  dS dS )z
        Creates a generator which returns the span's ``sentry-trace`` and ``baggage`` headers.
        If the span's containing transaction doesn't yet have a ``baggage`` value,
        this will cause one to be generated and stored.
        N)r3   r   to_traceparentget_baggage	serializer   )rT   rF   r?   r?   r@   iter_headers  s   zSpan.iter_headersc                 K   s(   t d |s	dS | jt|ifi |S )a  
        DEPRECATED: Use :py:meth:`sentry_sdk.tracing.Span.continue_from_headers`.

        Create a ``Transaction`` with the given params, then add in data pulled from
        the given ``sentry-trace`` header value before returning the ``Transaction``.
        zwDeprecated: Use Transaction.continue_from_headers(headers, **kwargs) instead of from_traceparent(traceparent, **kwargs)N)r   r   r   r   )r   traceparentr   r?   r?   r@   from_traceparent$  s   zSpan.from_traceparentc                 C   sN   | j du rd}n
| j du rd}nd }d| j| jf }|d ur%|d|f 7 }|S )NT1F0z%s-%sz-%s)r-   r)   r*   )rT   r-   r   r?   r?   r@   r   =  s   

zSpan.to_traceparentc                 C   s   | j r| j  S dS )zReturns the :py:class:`~sentry_sdk.tracing_utils.Baggage`
        associated with this ``Span``, if any. (Taken from the root of the span tree.)
        N)r3   r   rS   r?   r?   r@   
to_baggageL  s   
zSpan.to_baggagec                 C      || j |< d S rQ   )r   rT   keyrR   r?   r?   r@   set_tagU     zSpan.set_tagc                 C   r   rQ   )r   r   r?   r?   r@   set_dataY  r   zSpan.set_datac                 C   s"   t | j| jk r|| j|< d S d S rQ   )r|   r   r   )rT   flagresultr?   r?   r@   set_flag]  s   zSpan.set_flagc                 C   s
   || _ d S rQ   r1   rT   rR   r?   r?   r@   r   b     
zSpan.set_status c                 C   $   t jdtdd ||d| j|< dS z
        .. deprecated:: 2.28.0
            This function is deprecated and will be removed in the next major release.
        zq`set_measurement()` is deprecated and will be removed in the next major version. Please use `set_data()` instead.r   r   )rR   unitNr   r   r   r   rT   r7   rR   r   r?   r?   r@   set_measurementf     zSpan.set_measurementc                 C   s<   |d ur|  tjt| |d ur|  tj| d S d S d S rQ   )r   r	   	THREAD_IDr;   THREAD_NAMErT   	thread_idthread_namer?   r?   r@   
set_threadt  s   zSpan.set_threadc                 C   s   |d ur|  tj| d S d S rQ   )r   r	   PROFILER_IDrT   rH   r?   r?   r@   r   }  s   zSpan.set_profiler_idc                 C   s0   |  dt| | tj| | t| d S )Nzhttp.status_code)r   r;   r   r	   HTTP_STATUS_CODEr   rs   rT   http_statusr?   r?   r@   set_http_status  s
   zSpan.set_http_statusc                 C   s
   | j dkS )Nokr   rS   r?   r?   r@   
is_success  r   zSpan.is_successc                 C   s   | j durdS z%|rt|trt|tj}|| _ nt | j }| j	t
|d d | _ W n ty<   ttj| _ Y nw |pBt }t||  dS )aD  
        Sets the end timestamp of the span.

        Additionally it also creates a breadcrumb from the span,
        if the span represents a database or HTTP request.

        :param scope: The scope to use for this transaction.
            If not provided, the current scope will be used.
        :param end_timestamp: Optional timestamp that should
            be used as timestamp instead of the current time.

        :return: Always ``None``. The type is ``Optional[str]`` to match
            the return value of :py:meth:`sentry_sdk.tracing.Transaction.finish`.
        Ni  )microseconds)r   r   r>   r   r   r   r   r   r   r4   r   r   r   r   r   "maybe_create_breadcrumbs_from_span)rT   r5   end_timestampelapsedr?   r?   r@   r     s$   



zSpan.finishc              
   C   s   | j | j| j| j| j| j| j| j| jd	}| j	r| j	| j
d< | jdur.| j }|r.||d< t| jdkr:| j|d< | j
}|rC||d< i }|| j || j |rW||d< |S )	z5Returns a JSON-compatible representation of the span.)	r)   r*   r+   r,   r.   r/   r4   r   r6   r1   N_metrics_summaryr   measurementstagsdata)r)   r*   r+   r,   r.   r/   r4   r   r6   r1   r   r   to_jsonr|   r   r   r   r   )rT   r   metrics_summaryr   r   r?   r?   r@   r     s6   


zSpan.to_jsonc                 C   s   | j | j| j| j| j| jd}| jr| j|d< | jr#| j 	 |d< i }| j
tj}|d ur4||d< | j
tj}|d urC||d< |rI||d< |S )N)r)   r*   r+   r.   r/   r6   r1   dynamic_sampling_contextz	thread.idzthread.namer   )r)   r*   r+   r.   r/   r6   r1   r3   r   r  r   r   r	   r   r   )rT   r   r   r   r   r?   r?   r@   get_trace_context  s,   
zSpan.get_trace_contextc                 C   s"   | j tj}|d u rd S d|iS )NrH   )r   r   r	   r   r   r?   r?   r@   get_profile_context  s
   zSpan.get_profile_contextc                 C   s   t  \}}| || d S rQ   )r   r   r   r?   r?   r@   r     s   
zSpan.update_active_thread)NNNTNNNNNNNNr   Nr   NN)%r8   r9   r:   r   r   r{   r   r   r   r   r   propertyr3   r   SENTRYr   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r?   r?   r?   r@   r      sd    
D

*
/
	
	
&'!
r   c                       s   e Zd ZdZdZdddejf fdd	Zdd Zd	d
 Z	 fddZ
 fddZedd Zdd Z		d$dd fddZd%ddZdd Z fddZ fddZ fddZd d! Zd"d# Z  ZS )&r2   ai  The Transaction is the root element that holds all the spans
    for Sentry performance instrumentation.

    :param name: Identifier of the transaction.
        Will show up in the Sentry UI.
    :param parent_sampled: Whether the parent transaction was sampled.
        If True this transaction will be kept, if False it will be discarded.
    :param baggage: The W3C baggage header value.
        (see https://www.w3.org/TR/baggage/)
    :param source: A string describing the source of the transaction name.
        This will be used to determine the transaction's type.
        See https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations
        for more information. Default "custom".
    :param kwargs: Additional arguments to be passed to the Span constructor.
        See :py:class:`sentry_sdk.tracing.Span` for available arguments.
    )
r7   rC   rD   sample_rater   	_contexts_profile_continuous_profile_baggager   r   Nc                    s   t  jdi | || _|| _d | _|| _i | _i | _d | _d | _	|| _
| j
d u r+d n| j
 }|d ur9|| _d S t| j| _d S Nr?   )superr{   r7   rC   r
  rD   r   r  r  r  r  r   _generate_sample_randr)   )rT   r7   rD   rF   rC   r   baggage_sample_randr   r?   r@   r{   ,  s   

zTransaction.__init__c              
   C   s.   d| j j| j| j| j| j| j| j| j| j	f	 S )Nzb<%s(name=%r, op=%r, trace_id=%r, span_id=%r, parent_span_id=%r, sampled=%r, source=%r, origin=%r)>)
r   r8   r7   r.   r)   r*   r+   r-   rC   r6   rS   r?   r?   r@   r   J  s   zTransaction.__repr__c                 C   s   | j dup	| jdu S )zReturns whether the transaction might have been started.

        If this returns False, we know that the transaction was not started
        with sentry_sdk.start_transaction, and therefore the transaction will
        be discarded.
        NF)r}   r-   rS   r?   r?   r@   _possibly_started[  s   
zTransaction._possibly_startedc                    s4   |   s	td t   | jd ur| j  | S )NzTransaction was entered without being started with sentry_sdk.start_transaction.The transaction will not be sent to Sentry. To fix, start the transaction bypassing it to sentry_sdk.start_transaction.)r  r   debugr  r   r  rS   r  r?   r@   r   g  s   


zTransaction.__enter__c                    sB   | j d ur| j ||| | jd ur| j  t ||| d S rQ   )r  r   r  stopr  )rT   r   rR   r   r  r?   r@   r   w  s
   


zTransaction.__exit__c                 C   s   | S )znThe root element of the span tree.
        In the case of a transaction it is the transaction itself.
        r?   rS   r?   r?   r@   r3     s   
z"Transaction.containing_transactionc                 C   sF   |}|durt jdtdd |}t|tjr!t jdtdd |jS |S )z
        Logic to get the scope from the arguments passed to finish. This
        function exists for backwards compatibility with the old finish.

        TODO: Remove this function in the next major version.
        NzMThe `hub` parameter is deprecated. Please use the `scope` parameter, instead.   r   zDPassing a Hub to finish is deprecated. Please pass a Scope, instead.)r   r   r   r   r   Hubr5   )rT   	scope_arghub_argscope_or_hubr?   r?   r@   _get_scope_from_finish_args  s    z'Transaction._get_scope_from_finish_argsr0   c             	      s   | j durdS | ||}|p| jpt }t }| s dS | jdu r]| jdu r0t	
d nt	
d |jr[t|jr[|jrI|jjdkrId}nd}|jj|dd	 |jj|d
d	 dS | jsht	d d| _t || | js~| jdu r|t	d dS dd | jjD }t| jjt| }|| jj }d| _i }	|	| j |	d|  i |  }
|
dur|	d|
i d| jd| ji|	| j| j | j|d}|dkr||d< | jdur| j  r| j|d< d| _| j!|d< | j"dur| j"# }|r||d< |$|S )au  Finishes the transaction and sends it to Sentry.
        All finished spans in the transaction will also be sent to Sentry.

        :param scope: The Scope to use for this transaction.
            If not provided, the current Scope will be used.
        :param end_timestamp: Optional timestamp that should
            be used as timestamp instead of the current time.
        :param hub: The hub to use for this transaction.
            This argument is DEPRECATED. Please use the `scope`
            parameter, instead.

        :return: The event ID if the transaction was sent to Sentry,
            otherwise None.
        NFz.Discarding transaction because sampled = FalsezSDiscarding transaction because it was not started with sentry_sdk.start_transactionr   backpressurer
  r   )data_categoryr   zCTransaction has no name, falling back to `<unlabeled transaction>`.z<unlabeled transaction>z1Discarding transaction without sampling decision.c                 S   s   g | ]}|j d ur| qS rQ   )r   r   ).0r   r?   r?   r@   
<listcomp>  s
    
z&Transaction.finish.<locals>.<listcomp>traceprofilerC   )typer   transaction_infocontextsr   r   r4   rw   _dropped_spansr   r   )%r   r  r5   r   r   r   	is_activer}   r-   r   r  	transporthas_tracing_enabledr   monitordownsample_factorrecord_lost_eventr7   r   r  r   rw   r|   rx   r   r  r  r  rC   r   r4   r  validr   r   r   capture_event)rT   r5   r   r0   clientreasonfinished_spanslen_diffrx   r&  profile_contexteventr  r  r?   r@   r     s   









zTransaction.finishc                 C   r   r   r   r   r?   r?   r@   r   0  r   zTransaction.set_measurementc                 C   s   || j |< dS )a  Sets a context. Transactions can have multiple contexts
        and they should follow the format described in the "Contexts Interface"
        documentation.

        :param key: The name of the context.
        :param value: The information about the context.
        N)r  r   r?   r?   r@   set_context>  s   	zTransaction.set_contextc                    s    t  | | dd|i dS )zySets the status of the Transaction according to the given HTTP status.

        :param http_status: The HTTP status code.responsestatus_codeN)r  r   r6  r   r  r?   r@   r   I  s   zTransaction.set_http_statusc                    s,   t   }| j|d< | j|d< | j|d< |S )z<Returns a JSON-compatible representation of the transaction.r7   rC   r-   )r  r   r7   rC   r-   r   r  r?   r@   r   Q  s
   



zTransaction.to_jsonc                    s   t   }| jr| j|d< |S )Nr   )r  r  r   )rT   trace_contextr  r?   r@   r  \  s   

zTransaction.get_trace_contextc                 C   s    | j r| j jrt| | _ | j S )zReturns the :py:class:`~sentry_sdk.tracing_utils.Baggage`
        associated with the Transaction.

        The first time a new baggage with Sentry items is made,
        it will be frozen.)r  mutablerE   populate_from_transactionrS   r?   r?   r@   r   e  s   zTransaction.get_baggagec                 C   sf  t  }dj| jrd| j d nd| jd}t|js d| _dS | jdur-t| j| _	dS t
|jdr<|jd |n|d	 durF|d	 n|jd
 }t|dds_tdj|d d| _dS t|| _	|jrr|  j	d|jj   _	| j	stdj|t
|jdrdndd d| _dS | jt| j	k | _| jrtdj|d dS tdj|| j	d dS )aO  
        Sets the transaction's sampling decision, according to the following
        precedence rules:

        1. If a sampling decision is passed to `start_transaction`
        (`start_transaction(name: "my transaction", sampled: True)`), that
        decision will be used, regardless of anything else

        2. If `traces_sampler` is defined, its decision will be used. It can
        choose to keep or ignore any parent sampling decision, or use the
        sampling context data to make its own decision or to choose a sample
        rate for the transaction.

        3. If `traces_sampler` is not defined, but there's a parent sampling
        decision, the parent sampling decision will be used.

        4. If `traces_sampler` is not defined and there's no parent sampling
        decision, `traces_sample_rate` will be used.
        z{op}transaction <{name}><z> r   )r.   r7   FNtraces_samplerrD   traces_sample_rateTracing)rC   zN[Tracing] Discarding {transaction_description} because of invalid sample rate.)transaction_descriptionr   z?[Tracing] Discarding {transaction_description} because {reason}z"traces_sampler returned 0 or Falseztraces_sample_rate is set to 0)r@  r1  z,[Tracing] Starting {transaction_description}z}[Tracing] Discarding {transaction_description} because it's not included in the random sample (sampling rate = {sample_rate}))r@  r
  )r   r   formatr.   r7   r*  r   r-   r>   r
  callabler   r   r   r   r+  r,  r  r   r   
from_float)rT   sampling_contextr0  r@  r
  r?   r?   r@   _set_initial_sampling_decisionq  sf   



z*Transaction._set_initial_sampling_decisionr  r  )r8   r9   r:   r   r   rI   rX   r{   r   r  r   r   r  r3   r  r   r   r6  r   r   r  r   rE  __classcell__r?   r?   r  r@   r2     s8    

# 
	r2   c                   @   s   e Zd Zdd Zedd ZejfddZdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Z		d,dd d!d"Zd-d$d%Zd&d' Zd(d) Zd*d+ ZdS ).r   c                 C   s   d| j j S )Nz<%s>)r   r8   rS   r?   r?   r@   r     s   zNoOpSpan.__repr__c                 C      d S rQ   r?   rS   r?   r?   r@   r3        zNoOpSpan.containing_transactionc                 K   s   t  S rQ   )r   )rT   r   r   r?   r?   r@   r     rV   zNoOpSpan.start_childc                 C      dS )Nr   r?   rS   r?   r?   r@   r        zNoOpSpan.to_traceparentc                 C   rG  rQ   r?   rS   r?   r?   r@   r     rJ  zNoOpSpan.to_baggagec                 C   rG  rQ   r?   rS   r?   r?   r@   r     rJ  zNoOpSpan.get_baggagec                 C   s   t dS r  )iterrS   r?   r?   r@   r     s   zNoOpSpan.iter_headersc                 C   rG  rQ   r?   r   r?   r?   r@   r     rJ  zNoOpSpan.set_tagc                 C   rG  rQ   r?   r   r?   r?   r@   r     rJ  zNoOpSpan.set_datac                 C   rG  rQ   r?   r   r?   r?   r@   r     rJ  zNoOpSpan.set_statusc                 C   rG  rQ   r?   r   r?   r?   r@   r     rJ  zNoOpSpan.set_http_statusc                 C   rI  )NTr?   rS   r?   r?   r@   r     rJ  zNoOpSpan.is_successc                 C      i S rQ   r?   rS   r?   r?   r@   r   
  rJ  zNoOpSpan.to_jsonc                 C   rL  rQ   r?   rS   r?   r?   r@   r    rJ  zNoOpSpan.get_trace_contextc                 C   rL  rQ   r?   rS   r?   r?   r@   r    rJ  zNoOpSpan.get_profile_contextNr  c                C   rI  )z_
        The `hub` parameter is deprecated. Please use the `scope` parameter, instead.
        Nr?   )rT   r5   r   r0   r?   r?   r@   r     s   zNoOpSpan.finishr   c                 C   rG  rQ   r?   r   r?   r?   r@   r   #  rJ  zNoOpSpan.set_measurementc                 C   rG  rQ   r?   r   r?   r?   r@   r6  '  rJ  zNoOpSpan.set_contextc                 C   rG  rQ   r?   rz   r?   r?   r@   r   +  rJ  zNoOpSpan.init_span_recorderc                 C   rG  rQ   r?   )rT   rD  r?   r?   r@   rE  /  rJ  z'NoOpSpan._set_initial_sampling_decisionr  r  )r8   r9   r:   r   r  r3   r   r  r   r   r   r   r   r   r   r   r   r   r   r  r  r   r   r6  r   rE  r?   r?   r?   r@   r     s4    

r   c                 C   rG  rQ   r?   funcr?   r?   r@   r"  6  rH  r"  c                 C   rG  rQ   r?   rM  r?   r?   r@   r"  ;  rH  c                 C   s   ddl m} | r|| S |S )av  
    Decorator to start a child span under the existing current transaction.
    If there is no current transaction, then nothing will be traced.

    .. code-block::
        :caption: Usage

        import sentry_sdk

        @sentry_sdk.trace
        def my_function():
            ...

        @sentry_sdk.trace
        async def my_async_function():
            ...
    r   )start_child_span_decorator)sentry_sdk.tracing_utilsrO  )rN  rO  r?   r?   r@   r"  A  s   )rE   r   r   r  r*  r   ignore)r   rQ   )Qdecimalr   r   r   r   r   r   enumr   r   sentry_sdk.constsr   r   r	   'sentry_sdk.profiler.continuous_profilerr
   sentry_sdk.utilsr   r   r   r   r   typingr   collections.abcr   r   r   r   r   r   r   r   r   r   r   r   r   typing_extensionsr   r   r    r!   r"   (sentry_sdk.profiler.transaction_profilerr#   sentry_sdk._typesr$   r%   r&   r'   r(   rB   r;   rG   r   r   rI   r[   LOW_QUALITY_TRANSACTION_SOURCESrW   rY   SOURCE_FOR_STYLErs   rt   r   r2   r   r"  rP  rE   r   r   r  r*  r   catch_warningssimplefilterr   sentry_sdk.metricsr   r?   r?   r?   r@   <module>   s    ;'    +   O\

 
	$