
    Dj7              
          d dl Z d dlZd dlZd dlmZmZ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 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'Zd dl(m)Z)m*Z*m+Z+m,Z,  G d de#d      Z- G d de-d      Z. e#dde/i      Z0dZ1dZ2d Z3d!Z4d"Z5d#Z6d$Z7d%Z8e4gZ9e7e7e7e5e4e7e5e5e5d&	Z:d' Z; G d( d)      Z< G d* d+      Z= G d, d-e=      Z> G d. d/e=      Z?ered6d0       Z@ed1        Z@d6d2Z@d d3lAmBZBmCZCmDZDmEZEmFZF  ej                         5   ej                  d4eI       d d5lJmKZK ddd       y# 1 sw Y   yxY w)7    N)datetime	timedeltatimezone)INSTRUMENTER
SPANSTATUSSPANDATA)get_profiler_id)get_current_thread_metais_valid_sample_rateloggernanosecond_time)TYPE_CHECKING)CallableMappingMutableMapping)Any)Dict)Iterator)List)Optional)overload)	ParamSpec)Tuple)Union)TypeVar)	TypedDictUnpackPR)EventMeasurementUnitSamplingContextMeasurementValuec                       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<   y)
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     VC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\sentry_sdk/tracing.pyr%   r%   ,   s    	
 T< $$J	
 	
  	Y&''sr ( 778!%%"899	
 "!X	 	`r=   r%   F)totalc                   0    e Zd ZU eed<   	 eed<   	 ded<   y)TransactionKwargssourceparent_sampledBaggagebaggageN)r5   r6   r7   r8   r9   r:   r<   r=   r>   rA   rA   g   s     	 Pr=   rA   ProfileContextprofiler_idrE   zsentry-tracecustomurlrouteview	componenttask)	endpointfunction_namehandler_namemethod_and_path_patternpath
route_nameroute_patternuri_templaterI   c                 \   | dk  rt         j                  S d| cxk  rdk  rn 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(  rt         j                  S | dk(  rt         j                  S t         j                  S d| cxk  rd	k  ran t         j                  S | 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)http_status_codes    r>   get_span_status_from_http_codere      s    #}}	 	&3	&s"///$'''$000$111$---$,,,...	 	&3	& ### s"///$+++$))),,,###r=   c                        e Zd ZdZdZd Zd Zy)_SpanRecorderz5Limits the number of spans recorded in a transaction.maxlenspansc                 &    |dz
  | _         g | _        y )N   rh   selfri   s     r>   __init__z_SpanRecorder.__init__   s     qj
r=   c                     t        | j                        | j                  kD  rd |_        y | j                  j	                  |       y N)lenrj   ri   _span_recorderappend)rn   spans     r>   addz_SpanRecorder.add   s0    tzz?T[[("&DJJd#r=   N)r5   r6   r7   __doc__	__slots__ro   rv   r<   r=   r>   rg   rg      s    ?#I$r=   rg   c                      e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd Zd Zd Zd Z	d	 Z
ed
        Zej                  fdZed        Zed        Zd Zed        Zd Zd Zd Zd Zd Zd dZd Zd Zd Zd Zd!dZd Z d Z!d Z"d Z#y)"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,   _measurementsr1   _start_timestamp_monotonic_nsr.   	timestamp_tags_datars   r-   _context_manager_state_containing_transaction_local_aggregatorr2   r3   r4   Nc                 Z   |xs t        j                         j                  | _        |xs! t        j                         j                  dd  | _        || _        || _        || _        || _        |xs || _	        |	| _
        || _        || _        || _        i | _        i | _        i | _        |
| _        |;t%        j&                  dt(        d       | j                  xs |j                  | _        |$t+        j,                  t.        j0                        }n4t3        |t4              r$t+        j6                  |t.        j0                        }|| _        	 t;               | _        d | _         d | _!        d | _"        | jG                          | jI                  tK                      y # t>        $ r Y Jw xY w)N   z>The `hub` parameter is deprecated. Please use `scope` instead.   
stacklevel)&uuiduuid4hexr&   r'   r(   r)   r*   r+   r,   r.   r-   r2   r3   r{   r~   r   r   warningswarnDeprecationWarningr   nowr   utc
isinstancer;   fromtimestampr1   r   r|   AttributeErrorr}   rs   r   update_active_threadset_profiler_idr	   )rn   r&   r'   r(   r)   r*   r+   r,   r-   r.   r0   r1   r2   r3   r4   s                  r>   ro   zSpan.__init__  sm   $ !4DJJL$4$47$**,"2"223"7,&<#.;


'=$?MMP" 0syyDJ"&ll8<<8O/&44_hllSO.	 2A1BD.
 "!%!!#_./  		s   F 	F*)F*c                 >    | j                   t        |      | _         y y rq   )rs   rg   rm   s     r>   init_span_recorderzSpan.init_span_recorderQ  s     &"/"7D 'r=   c                 D    | j                   }|t               x}| _         |S rq   )r   LocalAggregator)rn   rvs     r>   _get_local_aggregatorzSpan._get_local_aggregatorV  s'    ##:*9*;;B'	r=   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__r5   r+   r,   r&   r'   r(   r*   r3   rn   s    r>   __repr__zSpan.__repr__]  sP    
 ''  ##
	
r=   c                     | j                   xs t        j                         }|j                  }| |_        ||f| _        | S rq   )r2   
sentry_sdkget_current_scoperu   r   )rn   r2   old_spans      r>   	__enter__zSpan.__enter__m  s;    

<j::<::
',h&7#r=   c                     || j                  t        j                         | j                  \  }}| `| j	                  |       ||_        y rq   )
set_statusr   rb   r   finishru   )rn   tyvaluetbr2   r   s         r>   __exit__zSpan.__exit__u  sB    OOJ55655x'E
r=   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    r>   r0   zSpan.containing_transaction  s     +++r=   c                    |j                  d      t        j                  dt        d       t	        j
                         j                  d   }||k7  r
t               S |j                  d| j                         t        d| j                  | j                  | j                  d|}| j                  xr | j                  j                  }|r|j                  |       |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,   zEThe `description` parameter is deprecated. Please use `name` instead.r   r   instrumenterr*   )r&   r(   r0   r<   )getr   r   r   r   
get_clientoptionsNoOpSpan
setdefaultr*   rz   r&   r'   r0   rs   rv   )rn   r   kwargsconfiguration_instrumenterchildspan_recorders         r>   start_childzSpan.start_child  s     ::m$0MMW" &0%:%:%<%D%D^%T"55:)T\\2 
]]<<#'#>#>
 	
 ''VD,G,G,V,V 	 e$r=   c                 z    | t         u rt        j                  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.)rz   r   warningr/   continue_from_headersEnvironHeaders)clsenvironr   s      r>   continue_from_environzSpan.continue_from_environ  s9    & $;NN9 001HSFSSr=   c                 d   | t         u rt        j                  d       t        j                  |j                  t                    }|j                  t        |i       t        |j                  t                    }|!|j                  |       |j                          t        di |}d|_        |S )z
        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.
        zXDeprecated: use Transaction.continue_from_headers instead of Span.continue_from_headers.Fr<   )rz   r   r   rD   from_incoming_headerr   BAGGAGE_HEADER_NAMEupdateextract_sentrytrace_dataSENTRY_TRACE_HEADER_NAMEfreezer/   r)   )r   headersr   rE   sentrytrace_kwargstransactions         r>   r   zSpan.continue_from_headers  s     $;NN9 ..w{{;N/OP*G455KK01
 )MM,-
 NN!+F+-2*r=   c              #      K   | j                   syt        | j                         f | j                   j                         j	                         }|rt
        |f yyw)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)r0   r   to_traceparentget_baggage	serializer   )rn   rE   s     r>   iter_headerszSpan.iter_headers  sZ      **
 &(;(;(===--99;EEG%w.. s   AAc                 d    t        j                  d       |sy | 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   s      r>   from_traceparentzSpan.from_traceparent  sC     	A	

 (s((%{3
7=
 	
r=   c                     | j                   du rd}n| j                   du rd}nd }| j                  d| j                  }||d|z  }|S )NT1F0-)r*   r&   r'   )rn   r*   r   s      r>   r   zSpan.to_traceparent&  sT    <<4G\\U"GG!%=G--Kr=   c                 P    | j                   r| j                   j                         S y)zReturns the :py:class:`~sentry_sdk.tracing_utils.Baggage`
        associated with this ``Span``, if any. (Taken from the root of the span tree.)
        N)r0   r   r   s    r>   
to_baggagezSpan.to_baggage5  s%    
 &&..::<<r=   c                 "    || j                   |<   y rq   )r~   rn   keyr   s      r>   set_tagzSpan.set_tag>      

3r=   c                 "    || j                   |<   y rq   )r   r   s      r>   set_datazSpan.set_dataB  r   r=   c                     || _         y rq   r.   rn   r   s     r>   r   zSpan.set_statusF  s	    r=   c                 (    ||d| j                   |<   y N)r   unitr{   rn   r4   r   r   s       r>   set_measurementzSpan.set_measurementJ      -2D#A4 r=   c                     |M| j                  t        j                  t        |             |!| j                  t        j                  |       y y y rq   )r   r   	THREAD_IDr8   THREAD_NAMErn   	thread_idthread_names      r>   
set_threadzSpan.set_threadN  sF      MM(,,c)n=&h22K@ ' !r=   c                 J    |!| j                  t        j                  |       y y rq   )r   r   PROFILER_IDrn   rG   s     r>   r   zSpan.set_profiler_idW  s!    "MM(..< #r=   c                     | j                  dt        |             | j                  t        j                  |       | j                  t        |             y )Nzhttp.status_code)r   r8   r   r   HTTP_STATUS_CODEr   re   rn   http_statuss     r>   set_http_statuszSpan.set_http_status\  s@    K 0	
 	h//=6{CDr=   c                      | j                   dk(  S )Nokr   r   s    r>   
is_successzSpan.is_successd  s    {{d""r=   c                    | j                   y	 |r<t        |t              r$t        j                  |t
        j                        }|| _         n8t               | j                  z
  }| j                  t        |dz        z   | _         |xs t        j                         }t        ||        y# t        $ r+ t        j                  t
        j                        | _         Y Xw xY w)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|   r1   r   r   r   r   r   "maybe_create_breadcrumbs_from_span)rn   r2   end_timestampelapseds       r>   r   zSpan.finishh  s      >>%	8mU3$,$:$:=(,,$WM!.)+d.P.PP!%!5!5	!(49 " 7557*5$7  	8%\\(,,7DN	8s   A6B* *1CCc           
         | j                   | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  d	}| j                  r| j                  | j                  d<   | j                  !| j                  j                         }|r||d<   t        | j                        dkD  r| j                  |d<   | j                  }|r||d<   | j                  }|r||d<   |S )z5Returns a JSON-compatible representation of the span.)	r&   r'   r(   r)   r+   r,   r1   r}   r3   r.   _metrics_summaryr   measurementstagsdata)r&   r'   r(   r)   r+   r,   r1   r}   r3   r.   r~   r   to_jsonrr   r{   r   )rn   r   metrics_summaryr	  r
  s        r>   r  zSpan.to_json  s    
 ||"11&*&A&A''++#33kk

 ;;#';;DJJx !!-"44<<>O)8%&t!!"Q&!%!3!3B~zzBvJzzBvJ	r=   c                    | j                   | j                  | j                  | j                  | j                  | j
                  d}| j                  r| j                  |d<   | j                  r+| j                  j                         j                         |d<   i }| j                  j                  t        j                        }|||d<   | j                  j                  t        j                        }|||d<   |r||d<   |S )N)r&   r'   r(   r+   r,   r3   r.   dynamic_sampling_contextz	thread.idzthread.namer
  )r&   r'   r(   r+   r,   r3   r.   r0   r   r  r   r   r   r   r   )rn   r   r
  r   r   s        r>   get_trace_contextzSpan.get_trace_context  s     ||"11''++kk
 ;;;;BxL&&++779RRT )* JJNN8#5#56	  )DjjnnX%9%9:""-DBvJ	r=   c                 b    | j                   j                  t        j                        }|y d|iS )NrG   )r   r   r   r   r   s     r>   get_profile_contextzSpan.get_profile_context  s4    jjnnX%9%9: ;
 	
r=   c                 B    t               \  }}| j                  ||       y rq   )r
   r   r   s      r>   r   zSpan.update_active_thread  s    !8!:	;	;/r=   )NNNTNNNNNNNNmanualN NN)$r5   r6   r7   rw   rx   ro   r   r   r   r   r   propertyr0   r   SENTRYr   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r<   r=   r>   rz   rz      s   :I6 ##>0D8

  	, 	, (4':': (T T T2 ' 'R/( 
 
0  BA=
E#$L#JB
0r=   rz   c                        e Zd ZdZdZdddef fd	Zd Zd Z fdZ	 fd	Z
ed
        Zd Z	 	 ddd fdZddZd Z fdZ fdZ fdZd Zd Z xZS )r/   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.
    )r4   rB   rC   sample_rater{   	_contexts_profile_baggager  Nc                     t        |   di | || _        || _        d | _        || _        i | _        i | _        d | _        || _	        y Nr<   )
superro   r4   rB   r  rC   r{   r  r  r  )rn   r4   rC   rE   rB   r   r   s         r>   ro   zTransaction.__init__  sU     	"6"	, 	  r=   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   r5   r4   r+   r&   r'   r(   r*   rB   r3   r   s    r>   r   zTransaction.__repr__  sU    
 ''		##	
r=   c                 >    | j                   duxs | 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)rs   r*   r   s    r>   _possibly_startedzTransaction._possibly_started*  s#     ""$.G$,,%2GGr=   c                     | j                         st        j                  d       t        |           | j
                  | 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   debugr!  r   r  )rn   r   s    r>   r   zTransaction.__enter__6  sL    %%'LL> 	==$MM##%r=   c                 z    | j                   | j                   j                  |||       t        |   |||       y rq   )r  r   r!  )rn   r   r   r   r   s       r>   r   zTransaction.__exit__F  s4    ==$MM""2ub1UB'r=   c                     | S )znThe root element of the span tree.
        In the case of a transaction it is the transaction itself.
        r<   r   s    r>   r0   z"Transaction.containing_transactionM  s	     r=   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.
        zMThe `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   Hubr2   )rn   	scope_arghub_argscope_or_hubs       r>   _get_scope_from_finish_argsz'Transaction._get_scope_from_finish_argsY  sb     !MM_" #LlJNN3MMV"  %%%r=   r-   c          	      "   | j                   y| j                  ||      }|xs" | j                  xs t        j                         }t        j
                         }|j                         sy| j                  | j                  du rt        j                  d       nt        j                  d       |j                  ryt        |j                        rd|j                  r|j                  j                  dkD  rd}nd}|j                  j!                  |d	       |j                  j!                  |d
	       y| j"                  st        j$                  d       d| _        t&        | Q  ||       | j                  s"| j                  t        j$                  d       y| j                  j*                  D cg c]  }|j                   |j-                           }}d| _        i }|j/                  | j0                         |j/                  d| j3                         i       | j5                         }	|	|j/                  d|	i       d| j"                  d| j6                  i|| j8                  | j                   | j:                  |d}
| j<                  0| j<                  j?                         r| j<                  |
d<   d| _        | j@                  |
d<   | jB                  !| jB                  j-                         }|r||
d<   |jE                  |
      S c c}w )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_categoryru   zCTransaction has no name, falling back to `<unlabeled transaction>`.z<unlabeled transaction>z1Discarding transaction without sampling decision.traceprofilerB   )typer   transaction_infocontextsr	  r}   r1   rj   r  r  )#r}   r/  r2   r   r   r   	is_activers   r*   r   r&  	transporthas_tracing_enabledr   monitordownsample_factorrecord_lost_eventr4   r   r!  r   rj   r  r   r  r  r  rB   r~   r1   r  validr{   r   capture_event)rn   r2   r  r-   clientreasonru   finished_spansr8  profile_contexteventr  r   s               r>   r   zTransaction.finishz  s   , >>% 003
 EEz'C'C'E&&(!&||u$MNi $7$G>>fnn&F&F&J+F*F  2262W   2262PyyNNU 2DIum,|| ||#RS ++11
~~) LLN
 
 #'$"8"8":;<224&OOY89 "99!)4;; 7 JJ#33#	
 ==$)<)<)>#}}E) DM $ 2 2n !!-"44<<>O,;()""5))W
s   5#Lc                 (    ||d| j                   |<   y r   r   r   s       r>   r   zTransaction.set_measurement  r   r=   c                 "    || j                   |<   y)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   s      r>   set_contextzTransaction.set_context  s     $sr=   c                 L    t         |   |       | j                  dd|i       y)zySets the status of the Transaction according to the given HTTP status.

        :param http_status: The HTTP status code.responsestatus_codeN)r!  r   rH  )rn   r   r   s     r>   r   zTransaction.set_http_status  s'    
 	,m[%ABr=   c                 ~    t         |          }| j                  |d<   | j                  |d<   | j                  |d<   |S )z<Returns a JSON-compatible representation of the transaction.r4   rB   r*   )r!  r  r4   rB   r*   )rn   r   r   s     r>   r  zTransaction.to_json  s=     W_YY6
{{89	r=   c                 Z    t         |          }| j                  r| j                  |d<   |S )Nr
  )r!  r  r   )rn   trace_contextr   s     r>   r  zTransaction.get_trace_context  s+    13::$(JJM&!r=   c                     | 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.)r  mutablerD   populate_from_transactionr   s    r>   r   zTransaction.get_baggage!  s3     }} 5 5#==dCDM}}r=   c           
         t        j                         }dj                  | j                  rd| j                  z   dz   nd| j                        }t        |j                        sd| _        y| j                  t        | j                        | _	        yt        |j                  j                  d            r |j                  d   |      n|d	   |d	   n|j                  d
   }t        |d      s-t        j                  dj                  |             d| _        yt        |      | _	        |j                  r,| xj                  d|j                  j                   z  z  c_	        | j                  sTt        j"                  dj                  |t        |j                  j                  d            rdnd             d| _        yt%        j$                         | j                  k  | _        | j                  r&t        j"                  dj                  |             yt        j"                  dj                  || j                               y)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}>r   z> r  )r+   r4   FNtraces_samplerrC   traces_sample_rateTracing)rB   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)rV  rB  z,[Tracing] Starting {transaction_description}z}[Tracing] Discarding {transaction_description} because it's not included in the random sample (sampling rate = {sample_rate}))rV  r  )r   r   formatr+   r4   r;  r   r*   r;   r  callabler   r   r   r   r<  r=  r&  random)rn   sampling_contextrA  rV  r  s        r>   _set_initial_sampling_decisionz*Transaction._set_initial_sampling_decision.  s!   * &&("<"C"C(,dgg$Rtyy #D #

 #6>>2 DL <<#$T\\2D **+;<= -FNN+,-=>
 $$45A !!12^^$89 	 $K	BNN`gg,C h 
 !DL ->>6>>#C#C CC LLQXX,C $FNN$6$67G$HI == Y 	 !DL
 }})9)99<<LL>EE,C F  LL P  W  W,C $ 0 0 W r=   r  r  )r5   r6   r7   rw   rx   TRANSACTION_SOURCE_CUSTOMro   r   r$  r   r   r  r0   r/  r   r   rH  r   r  r  r   r[  __classcell__)r   s   @r>   r/   r/     s    "
I ( .
"
H ( 	 	F z*
 z*xB	$C	fr=   r/   c                       e Zd Zd Zed        Zej                  fdZd Z	d Z
d Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Z	 	 ddddZddZd Zd Zd Zy)r   c                 4    d| j                   j                  z  S )Nz<%s>)r   r5   r   s    r>   r   zNoOpSpan.__repr__  s    ////r=   c                      y rq   r<   r   s    r>   r0   zNoOpSpan.containing_transaction  s     r=   c                     t               S rq   )r   )rn   r   r   s      r>   r   zNoOpSpan.start_child  s
    zr=   c                      y)Nr  r<   r   s    r>   r   zNoOpSpan.to_traceparent  s    r=   c                      y rq   r<   r   s    r>   r   zNoOpSpan.to_baggage      r=   c                      y rq   r<   r   s    r>   r   zNoOpSpan.get_baggage  rd  r=   c                     t        d      S r   )iterr   s    r>   r   zNoOpSpan.iter_headers  s    Bxr=   c                      y rq   r<   r   s      r>   r   zNoOpSpan.set_tag      r=   c                      y rq   r<   r   s      r>   r   zNoOpSpan.set_data  ri  r=   c                      y rq   r<   r   s     r>   r   zNoOpSpan.set_status  ri  r=   c                      y rq   r<   r   s     r>   r   zNoOpSpan.set_http_status  ri  r=   c                      y)NTr<   r   s    r>   r   zNoOpSpan.is_success  rd  r=   c                     i S rq   r<   r   s    r>   r  zNoOpSpan.to_json      	r=   c                     i S rq   r<   r   s    r>   r  zNoOpSpan.get_trace_context  ro  r=   c                     i S rq   r<   r   s    r>   r  zNoOpSpan.get_profile_context  ro  r=   Nr0  c                     y)z_
        The `hub` parameter is deprecated. Please use the `scope` parameter, instead.
        Nr<   )rn   r2   r  r-   s       r>   r   zNoOpSpan.finish  s     	r=   c                      y rq   r<   r   s       r>   r   zNoOpSpan.set_measurement  ri  r=   c                      y rq   r<   r   s      r>   rH  zNoOpSpan.set_context  ri  r=   c                      y rq   r<   rm   s     r>   r   zNoOpSpan.init_span_recorder  ri  r=   c                      y rq   r<   )rn   rZ  s     r>   r[  z'NoOpSpan._set_initial_sampling_decision  ri  r=   r  r  )r5   r6   r7   r   r  r0   r   r  r   r   r   r   r   r   r   r   r   r   r  r  r  r   r   rH  r   r[  r<   r=   r>   r   r     s    0   (4':':  
 r=   r   c                      y rq   r<   funcs    r>   r4  r4         	r=   c                      y rq   r<   rx  s    r>   r4  r4    rz  r=   c                 &    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_utilsr}  )ry  r}  s     r>   r4  r4     s    & D )$//))r=   )rD   r   r   r;  r  ignore)r   rq   )Lr   rY  r   r   r   r   r   sentry_sdk.constsr   r   r   'sentry_sdk.profiler.continuous_profilerr	   sentry_sdk.utilsr
   r   r   r   typingr   collections.abcr   r   r   r   r   r   r   r   r   r   r   r   r   typing_extensionsr   r   r   r   sentry_sdk.profilersentry_sdk._typesr    r!   r"   r#   r%   rA   r8   rF   r   r   r\  TRANSACTION_SOURCE_URLTRANSACTION_SOURCE_ROUTETRANSACTION_SOURCE_VIEWTRANSACTION_SOURCE_COMPONENTTRANSACTION_SOURCE_TASKLOW_QUALITY_TRANSACTION_SOURCESSOURCE_FOR_STYLEre   rg   rz   r/   r   r4  r~  rD   r   r   r;  r  catch_warningssimplefilterr   sentry_sdk.metricsr   r<   r=   r>   <module>r     s      2 2  @ @ C  !AA 3#AA 9aYe 9avQJe Q 3	
N   )  %  "   *    # 
 -107".-,#
 $$N$ $.I0 I0Xp$ pfYt Yx    
*>  X 3H($6723 3 3s   E77F 