
    tnig              
          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mZ d dl	Z	d dl
mZmZmZmZ d dlmZ d dlmZmZmZmZmZmZ erd dlmZmZmZ d d	lmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& d d
l'm(Z(m)Z)  e!d          Z* e$d          Z+d dl,m-Z-m.Z.m/Z/m0Z0 d dlm1Z1 d dl2m3Z3  G d de(d          Z4 G d de4d          Z5 e(dde6i          Z7dZ8dZ9 G d de6e          Z:e:j;        gZ<e:j=        e:j=        e:j=        e:j>        e:j;        e:j=        e:j>        e:j>        e:j>        d	Z?de@de6fdZA G d  d!          ZB G d" d#          ZC G d$ d%eC          ZD G d& d'eC          ZEer0e&	 d9dddejF        d(	 	 	 	 	 	 	 	 	 	 	 d:d2            ZGe&d;d4            ZG	 d9dddejF        d(	 	 	 	 	 	 	 	 	 	 	 d<d7ZGd d8lHmIZImJZJmKZKmLZLmMZMmNZN dS )=    N)datetime	timedeltatimezone)Enum)TYPE_CHECKING)INSTRUMENTERSPANDATA
SPANSTATUSSPANTEMPLATE)get_profiler_id)capture_internal_exceptionsget_current_thread_metais_valid_sample_rateloggernanosecond_timeshould_be_treated_as_error)CallableMappingMutableMapping)AnyDictIteratorListOptional	ParamSpecSetTupleTypeVarUnionoverload)	TypedDictUnpackPR)EventMeasurementUnitMeasurementValueSamplingContext)ContinuousProfile)Profilec                       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<   	 ded	<   	 eed
<   	 ded<   	 d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descriptionOptional[sentry_sdk.Hub]hubstatusOptional[Transaction]containing_transaction Optional[Union[datetime, float]]start_timestampzsentry_sdk.ScopescopeoriginnameN__name__
__module____qualname__str__annotations__bool     O/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/sentry_sdk/tracing.pyr,   r,   1   s         	
 T< $$$$J	
 	
  	Y''''sr 77778;;;;	
 "!!!X	 			``rF   r,   F)totalc                   2    e Zd ZU eed<   	 eed<   	 ded<   dS )TransactionKwargssourceparent_sampledBaggagebaggageNr>   rE   rF   rG   rJ   rJ   l   s=         	 PPrF   rJ   ProfileContextprofiler_idrN   zsentry-tracec                   2    e Zd ZdZdZdZdZdZdZde	fdZ
d	S )
TransactionSource	componentcustomroutetaskurlviewreturnc                     | j         S N)valueselfs    rG   __str__zTransactionSource.__str__   s
    zrF   N)r?   r@   rA   	COMPONENTCUSTOMROUTETASKURLVIEWrB   r_   rE   rF   rG   rR   rR      sM        IFED
CD      rF   rR   )	endpointfunction_namehandler_namemethod_and_path_patternpath
route_nameroute_patternuri_templaterW   http_status_coderY   c                    | dk     rt           j        S d| cxk    rdk     r{n nx| 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    rt           j        S | dk    rt           j        S t           j        S d| cxk    rd	k     rEn nB| d
k    rt           j	        S | dk    rt           j
        S | dk    rt           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)rn   s    rG   get_span_status_from_http_coder}      s,    #}	 	&	&	&	&3	&	&	&	&	&s""//$$''$$00$$11$$--$$,,..	 	&	&	&	&3	&	&	&	&	&s""//$$++$$)),,##rF   c                   .    e Zd ZdZdZdeddfdZd
d	ZdS )_SpanRecorderz5Limits the number of spans recorded in a transaction.maxlenspansdropped_spansr   rY   Nc                 6    |dz
  | _         g | _        d| _        d S )N   r   r   r^   r   s     rG   __init__z_SpanRecorder.__init__   s$     qj#%
"#rF   spanSpanc                     t          | j                  | j        k    rd |_        | xj        dz  c_        d S | j                            |           d S )Nr   )lenr   r   _span_recorderr   append)r^   r   s     rG   addz_SpanRecorder.add   sU    tz??T[(("&D!#Jd#####rF   )r   r   rY   N)r?   r@   rA   __doc__	__slots__intr   r   rE   rF   rG   r   r      sU        ??4I$s $t $ $ $ $$ $ $ $ $ $rF   r   c                      e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 d\ddddd	dd
edddddddddddddddddeddddfdZdeddfdZ	e
defd            Zej        deddfd             Ze
defd!            Zej        deddfd"            Zdefd#Zd]d$Z	 	 	 	 	 	 	 	 d^d(Ze
d_d)            Zej        fd*ed+d,dd fd-Ze	 	 	 	 	 	 d`d1            Zedd2	 	 	 	 	 	 	 dad5            Zdbd7Ze	 	 	 	 	 	 dcd9            Zdefd:Zddd<Zd=edd,ddfd>Zd=edd,ddfd?ZdedBZdCedDeddfdEZdeddfdFZ 	 dfdede!dHdIddfdJZ"	 	 	 	 	 	 dgdNZ#dhdPZ$dQeddfdRZ%defdSZ&	 	 di	 	 	 	 	 djdVZ'dkdWZ(dldXZ)dmdZZ*dnd[Z+dS )or   ak  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.
    )	_trace_id_span_idr/   r0   r1   r2   r3   _measurementsr:   _start_timestamp_monotonic_nsr6   	timestamp_tags_datar   r5   _context_manager_state_containing_transactionr;   r<   r=   _flags_flags_capacityNTmanualr-   Optional[str]r.   r/   r0   r1   Optional[bool]r2   r3   r5   r4   r6   r8   r7   r:   r9   r;   Optional[sentry_sdk.Scope]r<   r=   rY   c                    || _         || _        || _        || _        || _        || _        |p|| _        |	| _        || _        || _	        || _
        i | _        i | _        i | _        |
| _        i | _        d| _        |/t#          j        dt&          d           | j	        p|j	        | _	        |t)          j        t,          j                  }n4t1          |t2                    rt)          j        |t,          j                  }|| _        	 t9                      | _        n# t<          $ r Y nw xY wd | _        d | _         | !                                 | "                    tG                                 d S )N
   z>The `hub` parameter is deprecated. Please use `scope` instead.   
stacklevel)$r   r   r/   r0   r1   r2   r3   r6   r5   r;   r<   r   r   r   r   r   r   warningswarnDeprecationWarningr   nowr   utc
isinstancefloatfromtimestampr:   r   r   AttributeErrorr   r   update_active_threadset_profiler_idr   )r^   r-   r.   r/   r0   r1   r2   r3   r5   r6   r8   r:   r;   r<   r=   s                  rG   r   zSpan.__init__  s   " ",&<#.;
<>13
')
'=$)+!?MP"    0syDJ"&l8<88OO// 	T&4_hlSSO.	 2A1B1BD.. 	 	 	D	 049=!!###_../////s   D 
D)(D)r   c                 @    | j         t          |          | _         d S d S r[   )r   r   r   s     rG   init_span_recorderzSpan.init_span_recorder\  s)    &"/"7"7D '&rF   c                 X    | j         st          j                    j        | _         | j         S r[   )r   uuiduuid4hexr]   s    rG   r-   zSpan.trace_id`  s$    ~ 	.!Z\\-DN~rF   r\   c                     || _         d S r[   )r   r^   r\   s     rG   r-   zSpan.trace_idg  s    rF   c                 h    | j         s%t          j                    j        dd          | _         | j         S )N   )r   r   r   r   r]   s    rG   r.   zSpan.span_idk  s-    } 	2 JLL,RSS1DM}rF   c                     || _         d S r[   )r   r   s     rG   r.   zSpan.span_idr  s    rF   c                     d| j         j        d| j        d| j        d| j        d| j        d| j        d| j        d| j        d	S )
N<z(op=z, description:, trace_id=
, span_id=, parent_span_id=
, sampled=	, origin=)>)		__class__r?   r2   r3   r-   r.   r/   r1   r<   r]   s    rG   __repr__zSpan.__repr__v  sc      '''   ###
	
rF   c                 h    | j         pt          j                    }|j        }| |_        ||f| _        | S r[   )r;   
sentry_sdkget_current_scoper   r   )r^   r;   old_spans      rG   	__enter__zSpan.__enter__  s7    
<j:<<:
',h&7#rF   tyOptional[Any]tbc                    |/t          ||          r|                     t          j                   t	                      5  | j        \  }}| `|                     |           ||_        d d d            d S # 1 swxY w Y   d S r[   )r   
set_statusr
   r{   r   r   finishr   )r^   r   r\   r   r;   r   s         rG   __exit__zSpan.__exit__  s     !;B!F!FOOJ5666(** 	" 	""9OE8+KK!EJ		" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s    )A66A:=A:c                     | j         S )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   r]   s    rG   r8   zSpan.containing_transaction  s     ++rF   instrumenterkwargsr   c                    |                     d          t          j        dt          d           t	          j                    j        d         }||k    rt                      S |                    d| j	                   t          d	| j        | j        | j        d|}| j        o| 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.
        r3   NzEThe `description` parameter is deprecated. Please use `name` instead.r   r   r   r1   )r-   r/   r8   rE   )getr   r   r   r   
get_clientoptionsNoOpSpan
setdefaultr1   r   r-   r.   r8   r   r   )r^   r   r   configuration_instrumenterchildspan_recorders         rG   start_childzSpan.start_child  s     ::m$$0MW"    &0%:%<%<%D^%T"555::)T\222 
]<#'#>
 
 	
 
 'VD,G,V 	  	%e$$$rF   environMapping[str, str]Transactionc                 @    t          j        t          |          fi |S )ag  
        DEPRECATED: Use :py:meth:`sentry_sdk.continue_trace`.

        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.
        )r   continue_from_headersEnvironHeaders)clsr   r   s      rG   continue_from_environzSpan.continue_from_environ  s%    ( 01H1HSSFSSSrF   _sample_randheadersr   c                   t          j        d           t          j        |                    t
                    |          }|                    t
          |i           t          |                    t                              }|)|                    |           |	                                 t          di |}d|_        |S )a  
        DEPRECATED: Use :py:meth:`sentry_sdk.continue_trace`.

        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)
        z2Deprecated: use sentry_sdk.continue_trace instead.r   NFrE   )r   warningrM   from_incoming_headerr   BAGGAGE_HEADER_NAMEupdateextract_sentrytrace_dataSENTRY_TRACE_HEADER_NAMEfreezer   r0   )r   r   r   r   rN   sentrytrace_kwargstransactions          rG   r   zSpan.continue_from_headers  s    $ 	KLLL .KK+,,<
 
 
 	*G45555KK011
 
 )MM,---
 NN!++F++-2*rF   Iterator[Tuple[str, str]]c              #      K   | 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)r8   r   to_traceparentget_baggage	serializer   )r^   rN   s     rG   iter_headerszSpan.iter_headers  s       * 	
 F&(;(;(=(=====-99;;EEGG 	/%w......	/ 	/rF   traceparentc                 4    |sdS  | j         t          |ifi |S )z
        DEPRECATED: Use :py:meth:`sentry_sdk.continue_trace`.

        Create a ``Transaction`` with the given params, then add in data pulled from
        the given ``sentry-trace`` header value before returning the ``Transaction``.
        N)r   r   )r   r   r   s      rG   from_traceparentzSpan.from_traceparent#  s=      	4(s(%{3
 
7=
 
 	
rF   c                 p    | j         du rd}n| j         du rd}nd }| j        d| j        }||d|z  }|S )NT1F0-)r1   r-   r.   )r^   r1   r   s      rG   r   zSpan.to_traceparent6  s`    <4GG\U""GGG!%=KGG--KrF   Optional[Baggage]c                 F    | 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)r8   r   r]   s    rG   
to_baggagezSpan.to_baggageD  s)     & 	=.::<<<trF   keyc                     || j         |<   d S r[   )r   r^   r  r\   s      rG   set_tagzSpan.set_tagL      
3rF   c                     || j         |<   d S r[   )r   r  s      rG   set_datazSpan.set_dataO  r	  rF   dataDict[str, Any]c                 :    | j                             |           d S r[   )r   r   r^   r  s     rG   update_datazSpan.update_dataR  s    
$rF   flagresultc                 X    t          | j                  | j        k     r|| j        |<   d S d S r[   )r   r   r   )r^   r  r  s      rG   set_flagzSpan.set_flagU  s4    t{d222 &DK 32rF   c                     || _         d S r[   r6   r   s     rG   r   zSpan.set_statusY  s    rF    unitr&   c                 X    t          j        dt          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   )r\   r  Nr   r   r   r   r^   r=   r\   r  s       rG   set_measurementzSpan.set_measurement\  C     		
 	
 	
 	

 .3D#A#A4   rF   	thread_idOptional[int]thread_namec                     |Q|                      t          j        t          |                     |$|                      t          j        |           d S d S d S r[   )r  r	   	THREAD_IDrB   THREAD_NAMEr^   r  r!  s      rG   
set_threadzSpan.set_threadk  sZ      MM(,c)nn===&h2K@@@@@	 !  '&rF   rP   c                 N    |"|                      t          j        |           d S d S r[   )r  r	   PROFILER_IDr^   rP   s     rG   r   zSpan.set_profiler_idt  s-    "MM(.<<<<< #"rF   http_statusc                     |                      dt          |                     |                     t          j        |           |                     t          |                     d S )Nzhttp.status_code)r  rB   r  r	   HTTP_STATUS_CODEr   r}   r^   r*  s     rG   set_http_statuszSpan.set_http_statusx  s_    K 0 0	
 	
 	
 	h/===6{CCDDDDDrF   c                     | j         dk    S )Nokr  r]   s    rG   
is_successzSpan.is_success  s    {d""rF   end_timestamp Optional[Union[float, datetime]]c                    | j         dS 	 |r<t          |t                    rt          j        |t
          j                  }|| _         n6t                      | j        z
  }| j	        t          |dz            z   | _         n3# t          $ r& t          j        t
          j                  | _         Y nw xY w|pt          j                    }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   r:   r   r   r   r   r   "maybe_create_breadcrumbs_from_span)r^   r;   r2  elapseds       rG   r   zSpan.finish  s    & >%4	8 mU33 X$,$:=(,$W$WM!.)++d.PP!%!5	!(49 9 9 "  	8 	8 	8%\(,77DNNN	8 7577*5$777ts   A4B   -B0/B0c           
         | j         | j        | j        | j        | j        | j        | j        | j        | j        d	}| j	        r| j	        |d<   | j	        | j
        d<   t          | j                  dk    r
| j        |d<   | j
        }|r||d<   i }|                    | j                   |                    | j                   |r||d<   |S )z5Returns a JSON-compatible representation of the span.)	r-   r.   r/   r0   r2   r3   r:   r   r<   r6   r   measurementstagsr  )r-   r.   r/   r0   r2   r3   r:   r   r<   r6   r   r   r   r   r   r   )r^   rvr:  r  s       rG   to_jsonzSpan.to_json  s     |"1&*&A'+#3k
 
 
 
 ; 	/;BxL#';DJx t!""Q&&!%!3B~z 	BvJDK   DJ 	BvJ	rF   c                    | j         | j        | j        | j        | j        | j        d}| j        r
| j        |d<   | j        r.| j                                        	                                |d<   i }| j
                            t          j                  }|||d<   | j
                            t          j                  }|||d<   |r||d<   |S )N)r-   r.   r/   r2   r3   r<   r6   dynamic_sampling_contextz	thread.idzthread.namer  )r-   r.   r/   r2   r3   r<   r6   r8   r   r>  r   r   r	   r#  r$  )r^   r;  r  r  r!  s        rG   get_trace_contextzSpan.get_trace_context  s    |"1'+k 
  
 ; 	';BxL& 	+7799RRTT )* JNN8#566	  )DjnnX%9::""-D 	BvJ	rF   Optional[ProfileContext]c                 Z    | j                             t          j                  }|d S d|iS )NrP   )r   r   r	   r(  r)  s     rG   get_profile_contextzSpan.get_profile_context  s4    jnnX%9::4 ;
 	
rF   c                 T    t                      \  }}|                     ||           d S r[   )r   r&  r%  s      rG   r   zSpan.update_active_thread  s,    !8!:!:	;	;/////rF   )NNNTNNNNNNNNr   N)rY   r   r   r   r\   r   r   r   rY   NrY   r7   )r   r   r   r   rY   r   )r   r   r   r   r   r   rY   r   rY   r   )r   r   r   r   rY   r7   rY   r  r  r  rY   Nr  )r  r   r!  r   rY   N)rP   r   rY   NNN)r;   r   r2  r3  rY   r   rY   r  rY   r   )rY   r@  )rY   N),r?   r@   rA   r   r   rD   rB   r   r   r   propertyr-   setterr.   r   r   r   r8   r   SENTRYr   classmethodr   r   r   r   r   r  r  r  r  r  r   r   r  r&  r   r.  r1  r   r<  r?  rB  r   rE   rF   rG   r   r      s        :I8 %)#'*.'+$("'+*."&:>>B.2 $>0 >0!>0 !>0 (	>0
 !%>0 ">0 >0 %>0 (>0  >0 !8>0 <>0 ,>0 >0 >0  
!>0 >0 >0 >0D8 8 8 8 8 8 #    X _c d    _     X ^S T    ^
# 
 
 
 
   
"!
"*9
"?N
"	
" 
" 
" 
" , , , X, #/"5) ))AF)	) ) ) )V T$T T 
	T T T [T* 
 )-	) )$) &	)
 ) 
) ) ) [)V/ / / /& 
$
 
 
!	
 
 
 [
$        3  u           C    $               'S '$ '4 ' ' ' '      BDB BB %B->B	B B B BA(A7FA	A A A A= = = =E3 E4 E E E E#D # # # #
 /3<@'+' :' 
	' ' ' 'R! ! ! !F   @
 
 
 
0 0 0 0 0 0rF   r   c                   f    e Zd ZdZdZdddej        fdedddd	d
eddddf fdZdefdZ	de
fdZd7 fdZ	 	 	 	 	 	 	 	 d8 fdZed7d            Z	 	 	 	 	 	 d9dZdefdZ	 	 d:dd	 	 	 	 	 	 	 d; fd%Z	 d<deded&d'ddfd(Zd)edd*ddfd+Zd,eddf fd-Zd= fd/Zd> fd1Zd?d3Z	 	 	 	 d@d6Z xZS )Ar   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.
    )
r=   rK   rL   sample_rater   	_contexts_profile_continuous_profile_baggager   r  Nr=   rL   r   rN   r  rK   r   zUnpack[SpanKwargs]rY   c                 D    t                      j        di | || _        || _        d | _        || _        i | _        i | _        d | _        d | _	        || _
        | j
        d n| j
                                        }|	|| _        d S t          | j                  | _        d S NrE   )superr   r=   rK   rR  rL   r   rS  rT  rU  rV  r   _generate_sample_randr-   )r^   r=   rL   rN   rK   r   baggage_sample_randr   s          rG   r   zTransaction.__init__  s     	""6"""	.2,<>+--1BF  M)DDt}/I/I/K/K 	 * 3D 5dm D DDrF   c                     d| j         j        d| j        d| j        d| j        d| j        d| j        d| j        d| j        d	| j	        d
S )Nr   z(name=z, op=r   r   r   r   z	, source=r   r   )
r   r?   r=   r2   r-   r.   r/   r1   rK   r<   r]   s    rG   r   zTransaction.__repr__8  si      '''			###	
rF   c                 &    | 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   r1   r]   s    rG   _possibly_startedzTransaction._possibly_startedH  s     "$.G$,%2GGrF   c                     |                                  st          j        d           t                                                       | j        | 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   debugrY  r   rT  )r^   r   s    rG   r   zTransaction.__enter__S  si    %%'' 	L>   	=$M##%%%rF   r   r   r\   r   c                     | j         | j                             |||           | j        | j                                         t	                                          |||           d S r[   )rT  r   rU  stoprY  )r^   r   r\   r   r   s       rG   r   zTransaction.__exit__b  sg     =$M""2ub111#/$))+++UB'''''rF   c                     | S )znThe root element of the span tree.
        In the case of a transaction it is the transaction itself.
        rE   r]   s    rG   r8   z"Transaction.containing_transactionm  s	     rF   	scope_arg1Optional[Union[sentry_sdk.Scope, sentry_sdk.Hub]]hub_argr   c                     |}|t          j        dt          d           |}t          |t          j                  r#t          j        dt          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   Hubr;   )r^   rd  rf  scope_or_hubs       rG   _get_scope_from_finish_argsz'Transaction._get_scope_from_finish_argsx  s     !M_"    #LlJN33 	&MV"     %%rF   c                 b    d                     | j        rd| j        z   dz   nd| j                  S )Nz{op}transaction <{name}>r   z> r  )r2   r=   )formatr2   r=   r]   s    rG   _get_log_representationz#Transaction._get_log_representation  s=    )00(,7dg$$Rty 1 
 
 	
rF   r5   r;   r2  r3  r5   r4   r   c          	      h   | j         dS |                     ||          }|p| j        pt          j                    }t          j                    }|                                sdS | j        | j        du rt          j
        d           nt          j
        d           |j        rht          |j                  rT|j        r|j        j        dk    rd}nd}|j                            |d	           |j                            |d
	           dS | j        st          j        d           d| _        t'                                          ||           | j                            t.          j                  }|||j        d         v rt          j
        d                    |                                 | j        t.          j                 |j        d                              |j        rU|j                            dd	           t7          | j        j                  dz   }|j                            dd
|           d| _        | j        s| j        t          j        d           dS d | j        j        D             }t7          | j        j                  t7          |          z
  }	|	| j        j        z   }
d| _        i }|                    | j                   |                    d|                                  i           | !                                }||                    d|i           d| j        d| j"        i|| j#        | j         | j$        |d}|
dk    r|
|d<   | j%        *| j%        &                                r| j%        |d<   d| _%        | j'        |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   backpressurerR  r   )data_categoryr   zCTransaction has no name, falling back to `<unlabeled transaction>`.z<unlabeled transaction>trace_ignore_status_codesz[Tracing] Discarding {transaction_description} because the HTTP status code {status_code} is matched by trace_ignore_status_codes: {trace_ignore_status_codes})transaction_descriptionstatus_coders  event_processorr   )rr  quantityz1Discarding transaction without sampling decision.c                 D    g | ]}|j         	|                                S r[   )r   r<  ).0r   s     rG   
<listcomp>z&Transaction.finish.<locals>.<listcomp>  s2     
 
 
~) LLNN)))rF   traceprofilerK   )typer   transaction_infocontextsr:  r   r:   r   _dropped_spansr9  ))r   rk  r;   r   r   r   	is_activer   r1   r   r`  	transporthas_tracing_enabledr   monitordownsample_factorrecord_lost_eventr=   r   rY  r   r   r   r	   r,  rm  rn  r   r   r   r   rS  r?  rB  rK   r   r:   rT  validr   capture_event)r^   r;   r2  r5   clientreasonru  	num_spansfinished_spanslen_diffr   r  profile_contexteventr   s                 rG   r   zTransaction.finish  s   * >%4 /3.N.N3/
 /
 EEz'C'E'E&((!! 	4&|u$$MNNNNi    	Q$7$G$G 	Q> +fn&F&J&J+FF*F 2262WWW  2262PPP4y 	2NU   2DIum,,,jnnX%>??#v~.IJJJL q  x  x,0,H,H,J,J $
8+D E.4n3/ x       22%] 3      3 9::Q>	 22%Vi 3    !DL| 	 |#RSSS4
 
+1
 
 
 t*011C4G4GG 4#6#DD #'''$"8"8":":;<<<2244&OOY8999 "9!)4; 7 J#3#	
 	
 1&3E"#=$)<)<)>)>$#}E) DM $ 2n""5)))rF   r  r&   c                 X    t          j        dt          d           ||d| j        |<   dS r  r  r  s       rG   r  zTransaction.set_measurement1  r  rF   r  dict[str, Any]c                     || 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)rS  r  s      rG   set_contextzTransaction.set_context@  s     $srF   r*  c                 z    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.responseru  N)rY  r.  r  )r^   r*  r   s     rG   r.  zTransaction.set_http_statusJ  s>     	,,,m[%ABBBBBrF   r  c                     t                                                      }| j        |d<   | j        |d<   | j        |d<   |S )z<Returns a JSON-compatible representation of the transaction.r=   rK   r1   )rY  r<  r=   rK   r1   )r^   r;  r   s     rG   r<  zTransaction.to_jsonQ  s<    WW__Y6
{89	rF   r   c                 j    t                                                      }| j        r
| j        |d<   |S )Nr  )rY  r?  r   )r^   trace_contextr   s     rG   r?  zTransaction.get_trace_context[  s4    1133: 	/$(JM&!rF   rM   c                 h    | j         r| j         j        rt          j        |           | _         | 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.)rV  mutablerM   populate_from_transactionr]   s    rG   r   zTransaction.get_baggagec  s6     } 	D 5 	D#=dCCDM}rF   sampling_contextr(   c           
      &   t          j                    }|                                 }t          |j                  s	d| _        dS | j        t          | j                  | _        dS t          |j        	                    d                    r |j        d         |          n|d         |d         n|j        d         }t          |d          s1t          j        d                    |	                     d| _        dS t          |          | _        |j        r| xj        d
|j        j        z  z  c_        | j        s[t          j        d                    |t          |j        	                    d                    rdnd                     d| _        dS | j        | j        k     | _        | j        r*t          j        d                    |	                     dS t          j        d                    || j                             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.
        FNtraces_samplerrL   traces_sample_rateTracing)rK   zN[Tracing] Discarding {transaction_description} because of invalid sample rate.)rt  r   z?[Tracing] Discarding {transaction_description} because {reason}z"traces_sampler returned 0 or Falseztraces_sample_rate is set to 0)rt  r  z,[Tracing] Starting {transaction_description}z}[Tracing] Discarding {transaction_description} because it's not included in the random sample (sampling rate = {sample_rate}))rt  rR  )r   r   rn  r  r   r1   r   rR  callabler   r   r   r   rm  r  r  r`  r   )r^   r  r  rt  rR  s        rG   _set_initial_sampling_decisionz*Transaction._set_initial_sampling_decisionn  su   , &(("&">">"@"@ #6>22 	 DLF <#$T\22DF **+;<<==,FN+,-=>>>
 $$45A !!122^$89 	 $K	BBB 	N`gg,C h    
 !DLF --> 	D6>#C CC  	LQXX,C $FN$6$67G$H$HII><<= Y  	 	 	 !DLF (4+;;< 	L>EE,C F       L P  W  W,C $ 0 W      rF   )rY   r   rD  )rd  re  rf  re  rY   r   rJ  r;   r   r2  r3  r5   r4   rY   r   rI  rK  rL  )rY   rM   r  r(   rY   N)r?   r@   rA   r   r   rR   ra   rB   r   r   rD   r^  r   r   rM  r8   rk  rn  r   r   r  r  r   r.  r<  r?  r   r  __classcell__)r   s   @rG   r   r     s<        "I  +/'+'.E EE )E %	E
 E 'E 
E E E E E E8
# 
 
 
 
 	H4 	H 	H 	H 	H     	(!	(*9	(?N	(		( 	( 	( 	( 	( 	(    XF E 
&	   @
 
 
 
 
 /3<@R*
 +/R* R*+R* :R*
 (R* 
R* R* R* R* R* R*j BDB BB %B->B	B B B B$s $+; $ $ $ $ $C3 C4 C C C C C C          	 	 	 	c 1c	c c c c c c c crF   r   c            	       ^   e Zd ZdefdZed3d            Zej        fdedddd fdZ	defd	Z
d4dZd4dZd5dZdeddddfdZdeddddfdZd6dZdeddfdZdeddfdZdefdZd7dZd8dZd8dZ	 	 d9dd	 	 	 	 	 	 	 d:d&Z	 d;d(eded)d*ddfd+Zdedd,ddfd-Zd.eddfd/Z	 	 	 	 d<d2ZdS )=r   rY   c                      d| j         j        z  S )Nz<%s>)r   r?   r]   s    rG   r   zNoOpSpan.__repr__  s    ///rF   r7   c                     d S r[   rE   r]   s    rG   r8   zNoOpSpan.containing_transaction  s    trF   r   r   r   c                     t                      S r[   )r   )r^   r   r   s      rG   r   zNoOpSpan.start_child  s     zzrF   c                     dS )Nr  rE   r]   s    rG   r   zNoOpSpan.to_traceparent  s    rrF   r  c                     d S r[   rE   r]   s    rG   r  zNoOpSpan.to_baggage      trF   c                     d S r[   rE   r]   s    rG   r   zNoOpSpan.get_baggage  r  rF   r   c                      t          d          S rX  )iterr]   s    rG   r   zNoOpSpan.iter_headers  s    BxxrF   r  r\   Nc                     d S r[   rE   r  s      rG   r  zNoOpSpan.set_tag      rF   c                     d S r[   rE   r  s      rG   r  zNoOpSpan.set_data  r  rF   r  r  c                     d S r[   rE   r  s     rG   r  zNoOpSpan.update_data  r  rF   c                     d S r[   rE   r   s     rG   r   zNoOpSpan.set_status  r  rF   r*  c                     d S r[   rE   r-  s     rG   r.  zNoOpSpan.set_http_status  r  rF   c                     dS )NTrE   r]   s    rG   r1  zNoOpSpan.is_success  r  rF   c                     i S r[   rE   r]   s    rG   r<  zNoOpSpan.to_json      	rF   c                     i S r[   rE   r]   s    rG   r?  zNoOpSpan.get_trace_context  r  rF   c                     i S r[   rE   r]   s    rG   rB  zNoOpSpan.get_profile_context  r  rF   ro  r;   r   r2  r3  r5   r4   r   c                    dS )z_
        The `hub` parameter is deprecated. Please use the `scope` parameter, instead.
        NrE   )r^   r;   r2  r5   s       rG   r   zNoOpSpan.finish  	     	rF   r  r=   r  r&   c                     d S r[   rE   r  s       rG   r  zNoOpSpan.set_measurement  	     	rF   r  c                     d S r[   rE   r  s      rG   r  zNoOpSpan.set_context  r  rF   r   c                     d S r[   rE   r   s     rG   r   zNoOpSpan.init_span_recorder  r  rF   r  r(   c                     d S r[   rE   )r^   r  s     rG   r  z'NoOpSpan._set_initial_sampling_decision  r  rF   rE  rG  rF  rH  rK  rL  rJ  r  rI  r  )r?   r@   rA   rB   r   rM  r8   r   rO  r   r   r  r   r   r  r  r  r   r   r.  rD   r1  r<  r?  rB  r   r   r  r  r   r  rE   rF   rG   r   r     s       0# 0 0 0 0    X #/"5 AF	   
             3 u     C  $            3 4    D             
 /3<@

 +/
 
+
 :

 (
 

 
 
 
 BD  %->	   
s +;           1	     rF   r   r2   r=   
attributestemplatefuncr2   r   r=   r  Optional[dict[str, Any]]r  r   *Callable[[Callable[P, R]], Callable[P, R]]c                    d S r[   rE   )r  r2   r=   r  r  s        rG   r{  r{  '  r  rF   Callable[P, R]c                     d S r[   rE   )r  s    rG   r{  r{  3  r  rF   Optional[Callable[P, R]]AUnion[Callable[P, R], Callable[[Callable[P, R]], Callable[P, R]]]c                J    ddl m}  |||||          }| r ||           S |S )a
  
    Decorator to start a child span around a function call.

    This decorator automatically creates a new span when the decorated function
    is called, and finishes the span when the function returns or raises an exception.

    :param func: The function to trace. When used as a decorator without parentheses,
        this is the function being decorated. When used with parameters (e.g.,
        ``@trace(op="custom")``, this should be None.
    :type func: Callable or None

    :param op: The operation name for the span. This is a high-level description
        of what the span represents (e.g., "http.client", "db.query").
        You can use predefined constants from :py:class:`sentry_sdk.consts.OP`
        or provide your own string. If not provided, a default operation will
        be assigned based on the template.
    :type op: str or None

    :param name: The human-readable name/description for the span. If not provided,
        defaults to the function name. This provides more specific details about
        what the span represents (e.g., "GET /api/users", "process_user_data").
    :type name: str or None

    :param attributes: A dictionary of key-value pairs to add as attributes to the span.
        Attribute values must be strings, integers, floats, or booleans. These
        attributes provide additional context about the span's execution.
    :type attributes: dict[str, Any] or None

    :param template: The type of span to create. This determines what kind of
        span instrumentation and data collection will be applied. Use predefined
        constants from :py:class:`sentry_sdk.consts.SPANTEMPLATE`.
        The default is `SPANTEMPLATE.DEFAULT` which is the right choice for most
        use cases.
    :type template: :py:class:`sentry_sdk.consts.SPANTEMPLATE`

    :returns: When used as ``@trace``, returns the decorated function. When used as
        ``@trace(...)`` with parameters, returns a decorator function.
    :rtype: Callable or decorator function

    Example::

        import sentry_sdk
        from sentry_sdk.consts import OP, SPANTEMPLATE

        # Simple usage with default values
        @sentry_sdk.trace
        def process_data():
            # Function implementation
            pass

        # With custom parameters
        @sentry_sdk.trace(
            op=OP.DB_QUERY,
            name="Get user data",
            attributes={"postgres": True}
        )
        def make_db_query(sql):
            # Function implementation
            pass

        # With a custom template
        @sentry_sdk.trace(template=SPANTEMPLATE.AI_TOOL)
        def calculate_interest_rate(amount, rate, years):
            # Function implementation
            pass
    r   )create_span_decoratorr  )sentry_sdk.tracing_utilsr  )r  r2   r=   r  r  r  	decorators          rG   r{  r{  9  sX    T ?>>>>>%%	  I  yrF   )rM   r   rZ  r   r  r6  r[   )r  Nr2   r   r=   r   r  r  r  r   rY   r  )r  r  rY   r  )r  r  r2   r   r=   r   r  r  r  r   rY   r  )Or   r   r   r   r   enumr   typingr   r   sentry_sdk.constsr   r	   r
   r   'sentry_sdk.profiler.continuous_profilerr   sentry_sdk.utilsr   r   r   r   r   r   collections.abcr   r   r   r   r   r   r   r   r   r   r   r   r   r    typing_extensionsr!   r"   r#   r$   sentry_sdk._typesr%   r&   r'   r(   r)   (sentry_sdk.profiler.transaction_profilerr*   r,   rJ   rB   rO   r   r   rR   rd   LOW_QUALITY_TRANSACTION_SOURCESr`   rb   SOURCE_FOR_STYLEr   r}   r   r   r   r   DEFAULTr{  r  rM   r   rZ  r   r  r6  rE   rF   rG   <module>r     s     2 2 2 2 2 2 2 2 2 2                       N N N N N N N N N N N N C C C C C C                 lAAAAAAAAAA                          43333333	#AA            JIIIII@@@@@@9a 9a 9a 9a 9aYe 9a 9a 9a 9avQ Q Q Q QJe Q Q Q Q Y3	
 N   ) 
	 	 	 	 	T 	 	 	 # 
 "+&0%/06!#-&,%+"
 
 #$S #$S #$ #$ #$ #$L$ $ $ $ $ $ $ $.W0 W0 W0 W0 W0 W0 W0 W0tU U U U U$ U U UpN N N N Nt N N Nb  	 # $15#/#7	 		 	 		
 /	 !	 
6	 	 	 X	    X (,V  -1+3V V
$V 	V 	V
 +V V IV V V Vv                 rF   