
    Yf                     $   d dl Z d dl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
 d dlmZ d dlmZ d d	lmZ d d
lmZmZmZ d dlmZ d dlmZ d dlmZmZmZmZ d dlmZ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+ e%rd dl,m-Z-m.Z. d dl/m0Z0 d dl/m1Z1 d dl/m2Z2 d dl/m3Z3 d dl/m4Z4 d dl/m5Z5 d dl/m6Z6 d dl/m7Z7 d dl/m8Z8 d dl/m9Z9 d dl/m:Z: d dl/m;Z; d dl<m=Z= d dl$m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZG d d lmHZH d dlIZI e8d!      ZJ e:d"      ZK e:d#e1d$e0f   %      ZL e:d&      ZMdaN e(d'd(      ZO e(d)d(      ZPg ZQ G d* d+e      ZR G d, d-      ZSd. ZTd/ ZUd0 ZV G d1 d2eW      ZXed3        ZYed4        ZZed5        Z[ed6        Z\d7 Z]d d8l^m_Z_ e%rd dl^ZIyy)9    Ncopy)deque)contextmanager)Enum)datetimetimezonewraps)chain)
Attachment)DEFAULT_MAX_BREADCRUMBSFALSE_VALUESINSTRUMENTER)Profile)Session)Baggagehas_tracing_enablednormalize_incoming_dataPropagationContext)BAGGAGE_HEADER_NAMESENTRY_TRACE_HEADER_NAMENoOpSpanSpanTransaction)TYPE_CHECKING)capture_internal_exceptions
ContextVarevent_from_exceptionexc_info_from_errorlogger)MappingMutableMapping)Any)Callable)Deque)Dict)	Generator)Iterator)List)Optional)	ParamSpec)Tuple)TypeVar)Union)Unpack)

BreadcrumbBreadcrumbHintErrorProcessorEventEventProcessorExcInfoHintLogLevelStrSamplingContextType)TransactionKwargsPRF.)boundTisolation_scope)defaultcurrent_scopec                       e Zd ZdZdZdZdZy)	ScopeTypecurrent	isolationglobalmergedN)__name__
__module____qualname__CURRENT	ISOLATIONGLOBALMERGED     P/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/sentry_sdk/scope.pyrE   rE   b   s    GIFFrR   rE   c                        e Zd ZddZd Zd Zy)_ScopeManagerNc                     g | _         y N)_old_scopes)selfhubs     rS   __init__z_ScopeManager.__init__j   s
    rR   c                     t         j                         }| j                  j                  |       |j	                         }t
        j                  |       |S rW   )Scopeget_isolation_scoperX   appendfork_isolation_scopeset)rY   rA   forked_scopes      rS   	__enter__z_ScopeManager.__enter__n   sF    3350&++-\*rR   c                 b    | j                   j                         }t        j                  |       y rW   )rX   popra   rb   )rY   exc_type	exc_valuetb	old_scopes        rS   __exit__z_ScopeManager.__exit__y   s$    $$((*	Y'rR   rW   )rJ   rK   rL   r[   rd   rk   rQ   rR   rS   rU   rU   i   s    	(rR   rU   c                 .    t         j                  |        y rW   )global_event_processorsr_   )	processors    rS   add_global_event_processorro      s    ""9-rR   c                 0    t        | | j                        S )N)fsetdoc)property__doc__)fns    rS   _attr_setterrv      s    ,,rR   c                 .     t                fd       }|S )Nc                 l    | j                   sy 	 d| _          | g|i |d| _         S # d| _         w xY w)NFT)_should_capture)rY   argskwargsru   s      rS   wrapperz!_disable_capture.<locals>.wrapper   sA     ##	(#(D d,T,V,#'D 4D s   * 	3r
   )ru   r|   s   ` rS   _disable_capturer}      s     
2Y( ( NrR   c                   &   e Zd ZdZdZdOdZd Zed        Zed        Z	ed        Z
ed	        Zed
        Zed        ZdOdZed        ZdPdZd Zd Zd ZdPdZd Zd Zd Zd Zd Zd Zd Zd Zd Zed        Zd Z ed        Z!e"d        Z#e#jH                  d         Z#dPd!Z%ed"        Z&d# Z'e"d$        Z(e(jH                  d%        Z(e"d&        Z)e)jH                  d'        Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1	 	 	 	 	 dQd0Z2dOd1Z3de4jj                  dfd2Z6e4jj                  fd3Z7dRd4Z8dOd5Z9dOd6Z:dOd7Z;d8 Z<d9 Z=d: Z>d; Z?d< Z@d= ZA	 dPd>ZBd? ZCd@ ZDdA ZEdB ZFdC ZGdD ZHdE ZIdF ZJdG ZKdH ZLdI ZMdJ ZNeO	 dPdK       ZPdL ZQ	 	 	 	 	 	 dSdMZRdN ZSy)Tr]   zaThe scope holds extra information that should be sent with all
    events that belong to it.
    )_level_name_fingerprint_transaction_transaction_info_user_tags	_contexts_extras_breadcrumbs_event_processors_error_processorsry   _span_session_attachments_force_auto_session_tracking_profile_propagation_contextclient_type_last_event_idNc                     || _         g | _        g | _        d | _        d | _        t               | _        || j                  |       | j                          | j                         }| j                  |       d | _        y )N)incoming_data)r   r   r   r   r   NonRecordingClientr   
set_clientclear_load_trace_data_from_envgenerate_propagation_contextr   )rY   tyr   incoming_trace_informations       rS   r[   zScope.__init__   sx    
!#!#
$(!(*OOF#

%)%C%C%E"))8R)S #rR   c                 |   t         j                  | j                        }| j                  |_        | j                  |_        | j
                  |_        | j                  |_        | j                  |_        t        | j                        |_	        | j                  |_
        t        | j                        |_        t        | j                        |_        t        | j                        |_        t        | j                        |_        t!        | j"                        |_        t!        | j$                        |_        | j&                  |_        | j(                  |_        | j*                  |_        | j,                  |_        | j.                  |_        t!        | j0                        |_        | j2                  |_        |S )zs
        Returns a copy of this scope.
        This also creates a copy of all referenced data structures.
        )object__new__	__class__r   r   r   r   r   dictr   r   r   r   r   r   r   listr   r   r   ry   r   r   r   r   r   )rY   rvs     rS   __copy__zScope.__copy__   s9    ^^DNN+::KK	::++++#D$:$:;::

#DNN+$,,'
t001#D$:$:;#D$:$:;"&";";!11::mm*.*K*K't001mm	rR   c                     t         j                         }|/t        t        j                        }t         j                  |       |S )zM
        .. versionadded:: 2.0.0

        Returns the current scope.
        r   )_current_scopegetr]   rE   rM   rb   )clsrC   s     rS   get_current_scopezScope.get_current_scope   s<     '**, !Y%6%67M}-rR   c                 .    t         j                  |       y)z
        .. versionadded:: 2.0.0

        Sets the given scope as the new current scope overwriting the existing current scope.
        :param new_current_scope: The scope to set as the new current scope.
        N)r   rb   )r   new_current_scopes     rS   set_current_scopezScope.set_current_scope  s     	,-rR   c                     t         j                         }|/t        t        j                        }t         j                  |       |S )zO
        .. versionadded:: 2.0.0

        Returns the isolation scope.
        r   )ra   r   r]   rE   rN   rb   )r   rA   s     rS   r^   zScope.get_isolation_scope  s<     +..0"#y':':;O  1rR   c                 .    t         j                  |       y)z
        .. versionadded:: 2.0.0

        Sets the given scope as the new isolation scope overwriting the existing isolation scope.
        :param new_isolation_scope: The scope to set as the new isolation scope.
        N)ra   rb   )r   new_isolation_scopes     rS   set_isolation_scopezScope.set_isolation_scope"  s     	01rR   c                 N    t         t        t        j                        a t         S )zL
        .. versionadded:: 2.0.0

        Returns the global scope.
        r   )_global_scoper]   rE   rO   r   s    rS   get_global_scopezScope.get_global_scope-  s       !Y%5%56MrR   c                 6    | j                         j                  S )a  
        .. versionadded:: 2.2.0

        Returns event ID of the event most recently captured by the isolation scope, or None if no event
        has been captured. We do not consider events that are dropped, e.g. by a before_send hook.
        Transactions also are not considered events in this context.

        The event corresponding to the returned event ID is NOT guaranteed to actually be sent to Sentry;
        whether the event is sent depends on the transport. The event could be sent later or not at all.
        Even a sent event could fail to arrive in Sentry due to network issues, exhausted quotas, or
        various other reasons.
        )r^   r   r   s    rS   last_event_idzScope.last_event_id;  s     &&(777rR   c                    |r|rt        d      t        t        t              n	t               }t        j
                  |_        t        j                         }||j                  |       t        j                         }||j                  |       | |k7  r| |k7  r|j                  |        |(t        |      r
 ||       |S |j                  |       |S |r |j                  di | |S )z
        Merges global, isolation and current scope into a new scope and
        adds the given additional scope or additional scope kwargs to it.
        zcannot provide scope and kwargsrQ   )	TypeErrorr   r   r]   rE   rP   r   ra   r   update_from_scoper   callableupdate_from_kwargs)rY   additional_scopeadditional_scope_kwargsfinal_scoperA   rC   s         rS   _merge_scopeszScope._merge_scopesL  s      7=>>-:-Fd=)EG%,,*..0&))/:&**,$))-8= T_%<))$/'() -  --.>?
  %*K**E-DErR   c                    t         j                         }	 |j                  }||j	                         r|S t
        j                         }	 |j                  }||j	                         r|S 	 t        j                  }||j	                         r|S t               S # t        $ r d}Y w xY w# t        $ r d}Y aw xY w# t        $ r d}Y Mw xY w)a,  
        .. versionadded:: 2.0.0

        Returns the currently used :py:class:`sentry_sdk.Client`.
        This checks the current scope, the isolation scope and the global scope for a client.
        If no client is available a :py:class:`sentry_sdk.client.NonRecordingClient` is returned.
        N)r   r   r   AttributeError	is_activera   r   r   )r   rC   r   rA   s       rS   
get_clientzScope.get_clientn  s     '**,	"))F &"2"2"4M*..0	$++F &"2"2"4M	"))F &"2"2"4M!##/  	F	  	F	  	F	s5   B B+ ,B< B('B(+B98B9<C
	C
c                 6    ||| _        yt               | _        y)z
        .. versionadded:: 2.0.0

        Sets the client for this scope.

        :param client: The client to use in this scope.
            If `None` the client of the scope will be replaced by a :py:class:`sentry_sdk.NonRecordingClient`.

        N)r   r   )rY   r   s     rS   r   zScope.set_client  s     !' 2f8J8LrR   c                     t        |       }|S )zP
        .. versionadded:: 2.0.0

        Returns a fork of this scope.
        r   )rY   rc   s     rS   r`   z
Scope.fork  s     DzrR   c                    d}t         j                  j                  d      xs dj                         }|t        v}|ri }t         j                  j                  d      r*t         j                  j                  d      xs d|t
        <   t         j                  j                  d      r*t         j                  j                  d      xs d|t        <   |xs dS )z
        Load Sentry trace id and baggage from environment variables.
        Can be disabled by setting SENTRY_USE_ENVIRONMENT to "false".
        NSENTRY_USE_ENVIRONMENT SENTRY_TRACESENTRY_BAGGAGE)osenvironr   lowerr   r   r   )rY   r   sentry_use_environmentuse_environments       rS   r   zScope._load_trace_data_from_env  s     &*" JJNN34:
%' 	 1D)+&zz~~n-JJNN>28b ++CD zz~~./JJNN#34: ++>? *1T1rR   c                 "    t               | _        y)zt
        Creates a new propagation context and sets it as `_propagation_context`. Overwriting existing one.
        N)r   r   rY   s    rS   set_new_propagation_contextz!Scope.set_new_propagation_context  s    
 %7$8!rR   c                     |rt        j                  |      }||| _        | j                  t        j
                  k7  r| j                  | j                          yyy)a  
        Makes sure the propagation context is set on the scope.
        If there is `incoming_data` overwrite existing propagation context.
        If there is no `incoming_data` create new propagation context, but do NOT overwrite if already existing.
        N)r   from_incoming_datar   r   rE   rM   r   )rY   r   propagation_contexts      rS   r   z"Scope.generate_propagation_context  sZ     "4"G"G"V".,?)::***((0002 1 +rR   c                     | j                   y| j                         }||j                         | j                   _        | j                   j                  S )z
        Returns the Dynamic Sampling Context from the Propagation Context.
        If not existing, creates a new one.
        N)r   get_baggagedynamic_sampling_context)rY   baggages     rS   get_dynamic_sampling_contextz"Scope.get_dynamic_sampling_context  sU     $$,""$002 %%> ((AAArR   c                 ^   t         j                         }t        |j                        r&| j                  | j                  j                         S | j                  1| j                  j                  d| j                  j                  }|S t         j                         j                         S )z
        Returns the Sentry "sentry-trace" header (aka the traceparent) from the
        currently active span or the scopes Propagation Context.
        -)r]   r   r   optionsspanto_traceparentr   trace_idspan_idr^   get_traceparent)rY   rz   r{   r   traceparents        rS   r   zScope.get_traceparent  s     !!# v~~.4993H99++-- $$0))22))11K  ((*::<<rR   c                 l   t         j                         }t        |j                        r&| j                  | j                  j                         S | j                  8| j                  j                  }|t        j                  |       S t        |      S t         j                         j                         S )z
        Returns the Sentry "baggage" header containing trace information from the
        currently active span or the scopes Propagation Context.
        )r]   r   r   r   r   
to_baggager   r   r   from_optionsr^   r   )rY   rz   r{   r   r   s        rS   r   zScope.get_baggage  s     !!# v~~.4993H99'')) $$0))BB % (/++D11788 ((*6688rR   c                     | j                   y| j                   j                  | j                   j                  | j                   j                  | j	                         d}|S )zR
        Returns the Sentry "trace" context from the Propagation Context.
        N)r   r   parent_span_idr   )r   r   r   r   r   )rY   trace_contexts     rS   get_trace_contextzScope.get_trace_context  s]    
 $$, 11::0088"77FF(,(I(I(K	
 rR   c                     |j                  dd      }|t        j                  d       d}| j                         }||dt        d|dz  }| j                         }||dt        d|j                         dz  }|S )z
        Return meta tags which should be injected into HTML templates
        to allow propagation of trace information.
        r   NzaThe parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future.r   z<meta name="z" content="z">)rf   r!   warningr   r   r   r   	serialize)rY   rz   r{   r   metasentry_tracer   s          rS   trace_propagation_metazScope.trace_propagation_meta/  s     zz&$'NNs ++-#( D
 ""$#!!# D
 rR   c              #      K   | j                   S| j                         }|
t        |f | j                         }|$t	        |      j                         }t        |f yyyw)zz
        Creates a generator which returns the `sentry-trace` and `baggage` headers from the Propagation Context.
        N)r   r   r   r   r   r   r   )rY   r   dscr   s       rS   iter_headerszScope.iter_headersM  sm     
 $$0..0K&.;;335C!#,002)722  1s   A!A#c              /   F  K   t         j                         }|j                  j                  d      sy|j	                  dd      }|xs | j
                  }t        |j                        r||j                         D ]  }|  y| j                  | j                         D ]  }|  yt         j                         }|j                  |j                         D ]  }|  yt         j                         }|j                  |j                         D ]  }|  yyw)z
        Return HTTP headers which allow propagation of trace data. Data taken
        from the span representing the request, if available, or the current
        span on the scope if not.
        propagate_tracesNr   )r]   r   r   r   rf   r   r   r   r   r   r^   )rY   rz   r{   r   r   headerrC   rA   s           rS   iter_trace_propagation_headersz$Scope.iter_trace_propagation_headers\  s     !!#~~!!"45zz&$' tyyv~~.43C++- 
 ((4"//1 !F L! !& 7 7 9 55A"/"<"<"> %$% ',&?&?&AO&;;G&5&B&B&D )F"(L) Hs   DD!c                     | j                   | j                   S t        j                         }|j                   |j                   S t        j                         }|j                   |j                   S y rW   )r   r]   r   r^   )rY   rC   rA   s      rS   get_active_propagation_contextz$Scope.get_active_propagation_context  si    $$0,,,//1--9 555335//;"777rR   c                     d| _         d| _        d| _        i | _        d| _        i | _        i | _        i | _        g | _        | j                          d| _
        d| _        d| _        d| _        d| _        d| _        y)zClears the entire scope.NT)r   r   r   r   r   r   r   r   r   clear_breadcrumbsry   r   r   r   r   r   r   s    rS   r   zScope.clear  s       !#

 #
,0)$(!rR   c                 <    t        j                  d       || _        y)z
        When set this overrides the level.

        .. deprecated:: 1.0.0
            Use :func:`set_level` instead.

        :param value: The level to set.
        zIDeprecated: use .set_level() instead. This will be removed in the future.N)r!   r   r   rY   values     rS   levelzScope.level  s     	W	
 rR   c                     || _         y)zX
        Sets the level for the scope.

        :param value: The level to set.
        Nr   r   s     rS   	set_levelzScope.set_level  s     rR   c                     || _         y)z0When set this overrides the default fingerprint.N)r   r   s     rS   fingerprintzScope.fingerprint  s     "rR   c                 v    | j                   y| j                   j                  y| j                   j                  S )z8Return the transaction (root span) in the scope, if any.N)r   containing_transactionr   s    rS   transactionzScope.transaction  s8     :: ::,,4 zz000rR   c                     t        j                  d       || _        | j                  r3| j                  j                  r|| j                  j                  _        yyy)zrWhen set this forces a specific transaction name to be set.

        Deprecated: use set_transaction_name instead.z`Assigning to scope.transaction directly is deprecated: use scope.set_transaction_name() instead.N)r!   r   r   r   r  namer   s     rS   r  zScope.transaction  sI    $ 	n	
 "::$**;;5:DJJ--2 <:rR   c                     || _         | j                  rN| j                  j                  r8|| j                  j                  _        |r|| j                  j                  _        |r|| j
                  d<   yy)z?Set the transaction name and optionally the transaction source.sourceN)r   r   r  r
  r  r   )rY   r
  r  s      rS   set_transaction_namezScope.set_transaction_name  s^     !::$**;;59DJJ--2;A

118/5D""8, rR   c                 &    | j                  |       y)zPWhen set a specific user is bound to the scope. Deprecated in favor of set_user.N)set_userr   s     rS   userz
Scope.user   s     	erR   c                 x    || _         t        j                         j                  }||j	                  |       yy)zSets a user for the scope.N)r  )r   r]   r^   r   update)rY   r   sessions      rS   r  zScope.set_user  s8     
++-66NNN& rR   c                     | j                   S )z,Get/set current tracing span or transaction.)r   r   s    rS   r   z
Scope.span  s     zzrR   c                     || _         t        |t              rG|}|j                  r8|j                  | _        |j
                  r|j
                  | j                  d<   y y y y )Nr  )r   
isinstancer   r
  r   r  r   )rY   r   r  s      rS   r   z
Scope.span  sa     
 dK(K$/$4$4!%%7B7I7ID**84 &   )rR   c                     | j                   S rW   r   r   s    rS   profilezScope.profile!  s     }}rR   c                     || _         y rW   r  )rY   r  s     rS   r  zScope.profile&  s      rR   c                 "    || j                   |<   y)z
        Sets a tag for a key to a specific value.

        :param key: Key of the tag to set.

        :param value: Value of the tag to set.
        N)r   rY   keyr   s      rS   set_tagzScope.set_tag,  s      

3rR   c                 :    | j                   j                  |       y)a  Sets multiple tags at once.

        This method updates multiple tags at once. The tags are passed as a dictionary
        or other mapping type.

        Calling this method is equivalent to calling `set_tag` on each key-value pair
        in the mapping. If a tag key already exists in the scope, its value will be
        updated. If the tag key does not exist in the scope, the key-value pair will
        be added to the scope.

        This method only modifies tag keys in the `tags` mapping passed to the method.
        `scope.set_tags({})` is, therefore, a no-op.

        :param tags: A mapping of tag keys to tag values to set.
        N)r   r  )rY   tagss     rS   set_tagszScope.set_tags7  s    " 	

$rR   c                 <    | j                   j                  |d       y)zX
        Removes a specific tag.

        :param key: Key of the tag to remove.
        N)r   rf   rY   r  s     rS   
remove_tagzScope.remove_tagJ  s     	

sD!rR   c                 "    || j                   |<   y)zG
        Binds a context at a certain key to a specific value.
        N)r   r  s      rS   set_contextzScope.set_contextS  s     $srR   c                 <    | j                   j                  |d       y)zRemoves a context.N)r   rf   r#  s     rS   remove_contextzScope.remove_context^  s    
 	3%rR   c                 "    || j                   |<   y)z&Sets an extra key to a specific value.N)r   r  s      rS   	set_extrazScope.set_extrae  s     "SrR   c                 <    | j                   j                  |d       y)zRemoves a specific extra key.N)r   rf   r#  s     rS   remove_extrazScope.remove_extran  s    
 	d#rR   c                 "    t               | _        y)zClears breadcrumb buffer.N)r   r   r   s    rS   r   zScope.clear_breadcrumbsu  s     "GrR   c           	      V    | j                   j                  t        |||||             y)z)Adds an attachment to future events sent.)bytespathfilenamecontent_typeadd_to_transactionsN)r   r_   r   )rY   r/  r1  r0  r2  r3  s         rS   add_attachmentzScope.add_attachmentz  s/     	  !)$7	
rR   c                    t         j                         }|j                         st        j                  d       y|j
                  j                  d      }|j
                  j                  dt              }t        |xs d      }|j                  |       |syt        |xs d      }|j                  d      &t        j                  t        j                        |d<   |j                  d      d|d<   |
 |||      }n|}|| j                  j                  |       nt        j                  d	|       t!        | j                        |kD  r4| j                  j#                          t!        | j                        |kD  r3yy)
a  
        Adds a breadcrumb.

        :param crumb: Dictionary with the data as the sentry v7/v8 protocol expects.

        :param hint: An optional value that can be used by `before_breadcrumb`
            to customize the breadcrumbs that are emitted.
        z*Dropped breadcrumb because no client boundNbefore_breadcrumbmax_breadcrumbsrQ   	timestamptyperB   z)before breadcrumb dropped breadcrumb (%s))r]   r   r   r!   infor   r   r   r   r  r   nowr	   utcr   r_   lenpopleft)rY   crumbhintr{   r   r6  r7  	new_crumbs           rS   add_breadcrumbzScope.add_breadcrumb  sB    !!#!KKDE"NN../BC ..,,->@WXU[b!VDJB99[!)!)hll!;E+99V$%E&M()%6II $$Y/KKCUK$##$6%%' $##$6rR   c                    |j                  d|        t        j                         }|j                  d   }||k7  r
t	               S |xs i }|}|t        d	i |}|j                         |j                  d}|j                  |       |j                  |       t        |      }	|	j                  |       |j                  r4|j                  d   j                  d      xs d}
|j                  |
       |S )
ac  
        Start and return a transaction.

        Start an existing transaction if given, otherwise create and start a new
        transaction with kwargs.

        This is the entry point to manual tracing instrumentation.

        A tree structure can be built by adding child spans to the transaction,
        and child spans to other spans. To start a new child span within the
        transaction or any span, call the respective `.start_child()` method.

        Every child span must be finished before the transaction is finished,
        otherwise the unfinished spans are discarded.

        When used as context managers, spans and transactions are automatically
        finished at the end of the `with` block. If not using context managers,
        call the `.finish()` method.

        When the transaction is finished, it will be sent to Sentry with all its
        finished child spans.

        :param transaction: The transaction to start. If omitted, we create and
            start a new transaction.
        :param instrumenter: This parameter is meant for internal use only.
        :param custom_sampling_context: The transaction's custom sampling context.
        :param kwargs: Optional keyword arguments to be passed to the Transaction
            constructor. See :py:class:`sentry_sdk.tracing.Transaction` for
            available arguments.
        scopeinstrumenter)transaction_contextparent_sampled)sampling_context_experiments	max_spansi  )maxlenrQ   )
setdefaultr]   r   r   r   r   to_jsonrG  r  _set_initial_sampling_decisionr   sampledr   init_span_recorder)rY   r  rE  custom_sampling_contextr{   r   configuration_instrumentertransaction_kwargsrH  r  rJ  s              rS   start_transactionzScope.start_transaction  s
   L 	'4(!!#%+^^N%C"55:"9"?R $ %;(:;K
 $/#6#6#8)88
 	 7822DT2U+&..@P.Q 7;;KHQTI**)*<rR   c                    t               5  |j                  d|        t        j                         }|j                  d   }||k7  rt               cddd       S | j                  xs t        j                         j                  }|1d|vr!| j                         }||j                  |d<   t        di |}n |j                  di |}|cddd       S # 1 sw Y   yxY w)a  
        Start a span whose parent is the currently active span or transaction, if any.

        The return value is a :py:class:`sentry_sdk.tracing.Span` instance,
        typically used as a context manager to start and stop timing in a `with`
        block.

        Only spans contained in a transaction are sent to Sentry. Most
        integrations start a transaction at the appropriate time, for example
        for every incoming HTTP request. Use
        :py:meth:`sentry_sdk.start_transaction` to start a new transaction when
        one is not already in progress.

        For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Span`.
        rD  rE  Nr   rQ   )	new_scoperL  r]   r   r   r   r   r^   r   r   r   start_child)rY   rE  r{   r   rR  r   r   s          rS   
start_spanzScope.start_span  s    " [ 	gt,%%'F)/)G&99z	 	 99@ 9 9 ; @ @D|V+*.*M*M*O'*6-@-I-Iz*~f~ (t''1&13	 	 	s   ACA2CCc                 l    | j                  |       t        j                  t        |      |||      }|S )ze
        Sets the propagation context from environment or headers and returns a transaction.
        )opr
  r  )r   r   continue_from_headersr   )rY   environ_or_headersrZ  r
  r  r  s         rS   continue_tracezScope.continue_trace3  s=    
 	))*<=!77#$67	
 rR   c                     | j                  ||      }t        j                         j                  |||      }|)|j	                  d      dk7  r|| j                         _        |S )a}  
        Captures an event.

        Merges given scope data and calls :py:meth:`sentry_sdk.client._Client.capture_event`.

        :param event: A ready-made event that can be directly sent to Sentry.

        :param hint: Contains metadata about the event that can be read from `before_send`, such as the original exception object or a HTTP request object.

        :param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
            The `scope` and `scope_kwargs` parameters are mutually exclusive.

        :param scope_kwargs: Optional data to apply to event.
            For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`.
            The `scope` and `scope_kwargs` parameters are mutually exclusive.

        :returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.client._Client.capture_event`).
        )eventr@  rD  r9  r  )r   r]   r   capture_eventr   r^   r   )rY   r_  r@  rD  scope_kwargsevent_ids         rS   r`  zScope.capture_eventC  sc    ( ""5,7##%33%dRW3XEIIf$5$F8@D$$&5rR   c                 >    |d}||d} | j                   |fd|i|S )a  
        Captures a message.

        :param message: The string to send as the message.

        :param level: If no level is provided, the default level is `info`.

        :param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
            The `scope` and `scope_kwargs` parameters are mutually exclusive.

        :param scope_kwargs: Optional data to apply to event.
            For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`.
            The `scope` and `scope_kwargs` parameters are mutually exclusive.

        :returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.client._Client.capture_event`).
        r:  )messager   rD  )r`  )rY   rd  r   rD  ra  r_  s         rS   capture_messagezScope.capture_message`  s<    $ =E 

 "t!!%EuEEErR   c                 0   |t        |      }nt        j                         }t        |t        j                         j                        \  }}	  | j                  |f||d|S # t        $ r& | j                  t        j                                Y yw xY w)a  Captures an exception.

        :param error: An exception to capture. If `None`, `sys.exc_info()` will be used.

        :param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
            The `scope` and `scope_kwargs` parameters are mutually exclusive.

        :param scope_kwargs: Optional data to apply to event.
            For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`.
            The `scope` and `scope_kwargs` parameters are mutually exclusive.

        :returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.client._Client.capture_event`).
        N)client_options)r@  rD  )
r    sysexc_infor   r]   r   r   r`  	Exception_capture_internal_exception)rY   errorrD  ra  ri  r_  r@  s          rS   capture_exceptionzScope.capture_exception|  s     *51H||~H*U%5%5%7%?%?
t	=%4%%eT$eT|TT 	=,,S\\^<	=s   A& &,BBc                 2    t        j                  d|       y)z
        Capture an exception that is likely caused by a bug in the SDK
        itself.

        These exceptions do not end up in Sentry and are just logged instead.
        zInternal error in sentry_sdk)ri  N)r!   rl  )rY   ri  s     rS   rk  z!Scope._capture_internal_exception  s     	3hGrR   c                    |j                  dd      }| j                          t        j                         }t	        |j
                  j                  d      |j
                  j                  d      | j                  |      | _        y)zStarts a new session.session_modeapplicationreleaseenvironment)rr  rs  r  rp  N)	rf   end_sessionr]   r   r   r   r   r   r   )rY   rz   r{   rp  r   s        rS   start_sessionzScope.start_session  sh     zz.-@!!#NN&&y1**=9%	
rR   c                     | j                   }d| _         |4|j                          t        j                         j	                  |       yy)z)Ends the current session if there is one.N)r   closer]   r   capture_session)rY   rz   r{   r  s       rS   rt  zScope.end_session  s?     --MMO..w7 rR   c                 2    | j                          d| _        y)zStops automatic session tracking.

        This temporarily session tracking for the current scope when called.
        To resume session tracking call `resume_auto_session_tracking`.
        FN)rt  r   )rY   rz   r{   s      rS   stop_auto_session_trackingz Scope.stop_auto_session_tracking  s     	,1)rR   c                     d| _         y)zResumes automatic session tracking for the current scope if
        disabled earlier.  This requires that generally automatic session
        tracking is enabled.
        N)r   r   s    rS   resume_auto_session_trackingz"Scope.resume_auto_session_tracking  s     -1)rR   c                     t        | j                        dkD  r/t        j                  d| j                         | j                  dd= | j                  j	                  |       y)z}Register a scope local event processor on the scope.

        :param func: This function behaves like `before_send.`
           zLToo many event processors on scope! Clearing list to free up some memory: %rN)r=  r   r!   r   r_   )rY   funcs     rS   add_event_processorzScope.add_event_processor  sS     t%%&+NN^&& &&q)%%d+rR   c                 V    |
||fd}| j                   j                  |       y)a  Register a scope local error processor on the scope.

        :param func: A callback that works similar to an event processor but is invoked with the original exception info triple as second argument.

        :param cls: Optionally, only process exceptions of this type.
        Nc                 `    	 t        |d         }|r	 | |      S | S # t        $ r d}Y w xY w)N   F)r  rj  )r_  ri  is_instcls_	real_funcs      rS   r  z'Scope.add_error_processor.<locals>.func  sE    $(!d;G $UH55	 ! $#G$s    --)r   r_   )rY   r  r   r  r  s      @@rS   add_error_processorzScope.add_error_processor  s/     ?DI 	%%d+rR   c                 <    | j                   | j                   |d<   y y )Nr   r  rY   r_  r@  r   s       rS   _apply_level_to_eventzScope._apply_level_to_event  s    ;;"![[E'N #rR   c                 z    |j                  di       j                  dg       j                  | j                         y )Nbreadcrumbsvalues)rL  extendr   r  s       rS   _apply_breadcrumbs_to_eventz!Scope._apply_breadcrumbs_to_event  s3    +66xDKK	
rR   c                 `    |j                  d      | j                  | j                  |d<   y y y )Nr  )r   r   r  s       rS   _apply_user_to_eventzScope._apply_user_to_event
  s0    99V$)? JJE&M *@$rR   c                 `    |j                  d      | j                  | j                  |d<   y y y )Nr  )r   r   r  s       rS    _apply_transaction_name_to_eventz&Scope._apply_transaction_name_to_event  5    99]#+0A0A0M#'#4#4E-  1N+rR   c                 `    |j                  d      | j                  | j                  |d<   y y y )Ntransaction_info)r   r   r  s       rS    _apply_transaction_info_to_eventz&Scope._apply_transaction_info_to_event  s7    99'(0T5K5K5W(,(>(>E$% 6X0rR   c                 `    |j                  d      | j                  | j                  |d<   y y y )Nr  )r   r   r  s       rS   _apply_fingerprint_to_eventz!Scope._apply_fingerprint_to_event  r  rR   c                 t    | j                   r,|j                  di       j                  | j                          y y )Nextra)r   rL  r  r  s       rS   _apply_extra_to_eventzScope._apply_extra_to_event  s-    <<Wb)00> rR   c                 t    | j                   r,|j                  di       j                  | j                          y y )Nr   )r   rL  r  r  s       rS   _apply_tags_to_eventzScope._apply_tags_to_event#  s-    ::VR(//

; rR   c                 J   | j                   r+|j                  di       j                  | j                          |j                  di       }|j                  d      It	        |      r*| j
                  | j
                  j                         |d<   y | j                         |d<   y y )Ncontextstrace)r   rL  r  r   r   r   r   )rY   r_  r@  r   r  s        rS   _apply_contexts_to_eventzScope._apply_contexts_to_event(  s    >>Z,33DNNC##J3 << ("7+

0F$(JJ$@$@$B!$($:$:$<!	 )rR   c                 2    t        j                  d||       y )Nz%s (%s) dropped event)r!   r:  )rY   causer   s      rS   _dropzScope._drop6  s    +R7rR   c                 >   |j                  d      }|t        t        j                         j                  t        j                         j                  t        j                         j                        }|D ]#  } |||      }|| j                  |d      c S |}% |S )zX
        Runs the error processors on the event and returns the modified event.
        ri  zerror processor)r   r   r]   r   r   r^   r   r  )rY   r_  r@  ri  error_processorserror_processor	new_events          rS   run_error_processorszScope.run_error_processors;  s    
 88J'$&&(::))+=='');;  $4 "+E8<	$::o7HII!" rR   c                    |j                  d      }|dk(  }|st        j                         }t        j                         }t        t        t
        xr t
        j                  xs g |xr |j                  xs g |xr |j                  xs g       }|D ]8  }|}	t               5   |||      }	ddd       |	| j                  |d      c S |	}: |S # 1 sw Y   %xY w)zX
        Runs the event processors on the event and returns the modified event.
        r9  check_inNzevent processor)	r   ra   r   r   rm   r   r   r   r  )
rY   r_  r@  r   is_check_inrA   rC   event_processorsevent_processorr  s
             rS   run_event_processorszScope.run_event_processorsQ  s    
 YYvJ&.224O*..0M$'A-"A"AGREO$E$EKA-"A"AGR	  $4 "!	02 = /t <I=$::o7HII!" = =s   "
CC	c                    |j                  d      }|dk(  }|dk(  }|j                  d      xs g }| j                  D ]"  }|r|j                  s|j                  |       $ ||d<   | j	                  |||       |r'd|j                  di       j                  di       i|d<   |s| j                  |||       | j                  |||       | j                  |||       | j                  |||       | j                  |||       | j                  |||       | j                  |||       |s|s| j                  |||       | j                  ||      }|y| j                  ||      }|y|S )zBApplies the information contained on the scope to the given event.r9  r  r  attachmentsr  r  N)r   r   r3  r_   r  rL  r  r  r  r  r  r  r  r  r  r  )	rY   r_  r@  r   r   is_transactionr  attachments_to_send
attachments	            rS   apply_to_eventzScope.apply_to_evento  s    YYv},J&
 #hh}5;++ 	7J!Z%C%C#**:6	7 2]%%eT7; ))*b9==grJ!E* &&udG<,,UD'B%%eT7;11%wG11%wG%%eT7;&&udG<k,,UD'B))%6=))%6=rR   c                 "   |j                   |j                   | _         |j                  |j                  | _        |j                  |j                  | _        |j                  %| j                  j	                  |j                         |j
                  |j
                  | _        |j                  r%| j                  j	                  |j                         |j                  r%| j                  j	                  |j                         |j                  r%| j                  j	                  |j                         |j                  r%| j                  j                  |j                         |j                  r|j                  | _        |j                  r%| j                  j                  |j                         |j                  r|j                  | _        |j                  r|j                  | _        |j                  r|j                  | _        yy)z+Update the scope with another scope's data.N)r   r   r   r   r  r   r   r   r   r   r  r   r   r   r   r   )rY   rD  s     rS   r   zScope.update_from_scope  sw    <<#,,DK) % 2 2D) % 2 2D"".""))%*A*AB;;"DJ;;JJekk*??NN!!%//2==LL.$$U%7%78;;DJ$$U%7%78>>!NNDM%%(-(B(BD%>>!NNDM rR   c                     ||| _         ||| _        || j                  j                  |       || j                  j                  |       || j
                  j                  |       ||| _        yy)zUpdate the scope's attributes.N)r   r   r   r  r   r   r   )rY   r  r   extrasr  r   r  s          rS   r   zScope.update_from_kwargs  sy     DKDJLL'NN!!(+JJd#" +D #rR   c           	          d| j                   j                  dt        t        |             d| j                  d| j
                  d	S )N<z id=z name=z type=>)r   rJ   hexidr   r   r   s    rS   __repr__zScope.__repr__  s4     NN##4MJJJJ	
 	
rR   )NNrW   )NNNNF)NNN)NNNNNN)TrJ   rK   rL   rt   	__slots__r[   r   classmethodr   r   r^   r   r   r   r   r   r   r`   r   r   r   r   r   r   r   r   r   r   r   r   rv   r   r  r  rs   r  setterr  r  r  r   r  r  r!  r$  r&  r(  r*  r,  r   r4  rB  r   SENTRYrT  rX  r]  r`  re  rm  rk  ru  rt  rz  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r}   r  r   r   r  rQ   rR   rS   r]   r]      s   I6#.!F   . .   2 2   8 8  D #$ #$JM2693 B"=.92"<3")H)2    " "
 1 1" ; ;06  
'  
 
[[
J 
J   ^^   
	  &"	$&"$$ !
(*(\ !(( $	KZ '3&9&9 *X :F8>
H
821,( ,8)

'
5
?
5
?
<
=
,< 
 	1 1f+D ,0
rR   r]   c               #      K   t         j                         } | j                         }t        j	                  |      }	 | t        j                  |       y# t        j                  |       w xY ww)a  
    .. versionadded:: 2.0.0

    Context manager that forks the current scope and runs the wrapped code in it.
    After the wrapped code is executed, the original scope is restored.

    Example Usage:

    .. code-block:: python

        import sentry_sdk

        with sentry_sdk.new_scope() as scope:
            scope.set_tag("color", "green")
            sentry_sdk.capture_message("hello") # will include `color` tag.

        sentry_sdk.capture_message("hello, again") # will NOT include `color` tag.

    N)r]   r   r`   r   rb   reset)rC   rV  tokens      rS   rV  rV    s\     . ++-M""$Iy)E$ 	U#U#s   :A1A A1A..A1c              #      K   t         j                  |       }	 |  t         j                  |       y# t         j                  |       w xY ww)ag  
    .. versionadded:: 2.0.0

    Context manager that uses the given `scope` and runs the wrapped code in it.
    After the wrapped code is executed, the original scope is restored.

    Example Usage:
    Suppose the variable `scope` contains a `Scope` object, which is not currently
    the active scope.

    .. code-block:: python

        import sentry_sdk

        with sentry_sdk.use_scope(scope):
            scope.set_tag("color", "green")
            sentry_sdk.capture_message("hello") # will include `color` tag.

        sentry_sdk.capture_message("hello, again") # will NOT include `color` tag.

    N)r   rb   r  )rD  r  s     rS   	use_scoper    s@     2 u%E$ 	U#U#s   A3 AA

Ac               #     K   t         j                         } | j                         }t        j	                  |      }t         j                         }|j                         }t        j	                  |      }	 | t        j                  |       t        j                  |       y# t        j                  |       t        j                  |       w xY ww)am  
    .. versionadded:: 2.0.0

    Context manager that forks the current isolation scope and runs the wrapped code in it.
    The current scope is also forked to not bleed data into the existing current scope.
    After the wrapped code is executed, the original scopes are restored.

    Example Usage:

    .. code-block:: python

        import sentry_sdk

        with sentry_sdk.isolation_scope() as scope:
            scope.set_tag("color", "green")
            sentry_sdk.capture_message("hello") # will include `color` tag.

        sentry_sdk.capture_message("hello, again") # will NOT include `color` tag.

    N)r]   r   r`   r   rb   r^   ra   r  )rC   forked_current_scopecurrent_tokenrA   r   isolation_tokens         rS   rA   rA   +  s     0 ++-M(--/"&&';<M //1O)..0&**+>?O0!! 	]+/ 	]+/s   A3C6B% :+C%,CCc              #   d  K   t         j                         }|j                         }t        j	                  |      }t
        j	                  |       }	 |  t        j                  |       t
        j                  |       y# t        j                  |       t
        j                  |       w xY ww)al  
    .. versionadded:: 2.0.0

    Context manager that uses the given `isolation_scope` and runs the wrapped code in it.
    The current scope is also forked to not bleed data into the existing current scope.
    After the wrapped code is executed, the original scopes are restored.

    Example Usage:

    .. code-block:: python

        import sentry_sdk

        with sentry_sdk.isolation_scope() as scope:
            scope.set_tag("color", "green")
            sentry_sdk.capture_message("hello") # will include `color` tag.

        sentry_sdk.capture_message("hello, again") # will NOT include `color` tag.

    N)r]   r   r`   r   rb   ra   r  )rA   rC   r  r  r  s        rS   use_isolation_scoper  U  s     0 ++-M(--/"&&';<M '**?;O0 	]+/ 	]+/s   AB0B +B0,B--B0c                  F    t         j                         j                         S )z<Shortcut for `Scope.get_client().should_send_default_pii()`.)r]   r   should_send_default_piirQ   rR   rS   r  r  }  s     5577rR   )r   )`r   rh  r   collectionsr   
contextlibr   enumr   r   r	   	functoolsr   	itertoolsr   sentry_sdk.attachmentsr   sentry_sdk.constsr   r   r   sentry_sdk.profilerr   sentry_sdk.sessionr   sentry_sdk.tracing_utilsr   r   r   r   sentry_sdk.tracingr   r   r   r   r   sentry_sdk._typesr   sentry_sdk.utilsr   r   r   r    r!   collections.abcr"   r#   typingr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   typing_extensionsr0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   
sentry_sdkr<   r=   r>   r@   r   ra   r   rm   rE   rU   ro   rv   r}   r   r]   rV  r  rA   r  r  sentry_sdk.clientr   rQ   rR   rS   <module>r     s   	 
   %  '   - Q Q ' &   ,  7  (   5#AA8CH-.AA  />  OT:  ( (,.
-
 I
F I
X* $ $D $ $D &0 &0R $0 $0N8 1 rR   