o
    Zh                     @   s  d dl m Z  d dlmZ d dlmZ d dlZd dlZd dl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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& e!rd 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)m0Z0 d dl)m1Z1 d dl)m2Z2 d dl)m3Z3 d dl)m4Z4 d dl m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z= d dl>Z>e3de+de*f dZ?e3dZ@g ZAd d! ZBd"d# ZCd$d% ZDd&d' ZEG d(d) d)eFZGdS )*    )copy)deque)chainN)
Attachment)datetime_utcnow)FALSE_VALUESINSTRUMENTERwraps)Profile)Session)Baggageextract_sentrytrace_datahas_tracing_enablednormalize_incoming_data)BAGGAGE_HEADER_NAMESENTRY_TRACE_HEADER_NAMENoOpSpanSpanTransaction)TYPE_CHECKING)event_from_exceptionexc_info_from_errorloggercapture_internal_exceptions)MutableMapping)Any)Callable)Deque)Dict)	Generator)Iterator)List)Optional)Tuple)TypeVar)Union)	
BreadcrumbBreadcrumbHintErrorProcessorEventEventProcessorExcInfoHintLogLevelStrTypeF.)boundTc                 C   s   t |  d S N)global_event_processorsappend)	processor r7   G/var/www/html/lang_env/lib/python3.10/site-packages/sentry_sdk/scope.pyadd_global_event_processorG      r9   c                 C   s   t | | jdS )N)fsetdoc)property__doc__fnr7   r7   r8   _attr_setterL   r:   rA   c                    s   t   fdd}|S )Nc                    s8   | j sd S zd| _  | g|R i |W d| _ S d| _ w )NFT)_should_capture)selfargskwargsr?   r7   r8   wrapperS   s   z!_disable_capture.<locals>.wrapperr	   )r@   rF   r7   r?   r8   _disable_captureQ   s   
rG   c                 C   sj   |r|rt d|d ur!t| }t|r|| |S || |S |r1t| }|jdi | |S | }|S )Nzcannot provide scope and kwargsr7   )	TypeErrorr   callableupdate_from_scopeupdate_from_kwargs)baseZscope_changescope_kwargsZfinal_scoper7   r7   r8   _merge_scopesa   s   
	rN   c                   @   st  e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	d~ddZ
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zed d! Zd"d# Zed$d% Zed&d' Zejd(d' Zd~d)d*Zed+d, Zd-d. Zed/d0 Zejd1d0 Zed2d3 Zejd4d3 Zd5d6 Zd7d8 Z d9d: Z!d;d< Z"d=d> Z#d?d@ Z$dAdB Z%					CddDdEZ&ddFdGZ'de(j)fdHdIZ*de(j)fdJdKZ+ddLdMZ,ddNdOZ-	ddPdQZ.ddRdSZ/dTdU Z0dVdW Z1dXdY Z2dZd[ Z3d\d] Z4d^d_ Z5	d~d`daZ6dbdc Z7ddde Z8dfdg Z9dhdi Z:djdk Z;dldm Z<dndo Z=dpdq Z>drds Z?e@	d~dtduZAdvdw ZB						ddxdyZCdzd{ ZDd|d} ZEdS )ScopezaThe 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_processorsrB   _span_session_attachments_force_auto_session_tracking_profile_propagation_contextc                 C   s8   g | _ g | _d | _d | _|   |  }| j|d d S )N)incoming_data)rZ   r[   rQ   ra   clear_load_trace_data_from_envgenerate_propagation_context)rC   incoming_trace_informationr7   r7   r8   __init__   s   zScope.__init__c                 C   sp   d}t jdp	d }|tv}|r4i }t jdr$t jdp!d|t< t jdr4t jdp1d|t< |p7dS )z
        Load Sentry trace id and baggage from environment variables.
        Can be disabled by setting SENTRY_USE_ENVIRONMENT to "false".
        NZSENTRY_USE_ENVIRONMENT ZSENTRY_TRACEZSENTRY_BAGGAGE)osenvirongetlowerr   r   r   )rC   rf   Zsentry_use_environmentZuse_environmentr7   r7   r8   rd      s   zScope._load_trace_data_from_envc                 C   s   i }t |}|t}|rt| |d< |t}|r*t|}|d ur*|| d|v o1d|v}|r;|| 	  |rO|dsMt
 jdd  |d< |S d S )Ndynamic_sampling_contexttrace_idspan_id   )r   rk   r   r   Zfrom_incoming_headerrm   r   r   update_create_new_propagation_contextuuiduuid4hex)rC   datacontextZnormalized_dataZbaggage_headerZsentry_trace_headerZsentrytrace_dataZonly_baggage_no_sentry_tracer7   r7   r8   _extract_propagation_context   s.   



z"Scope._extract_propagation_contextc                 C   s"   t  jt  jdd  d d dS )Nrp   rn   ro   parent_span_idrm   )rs   rt   ru   rC   r7   r7   r8   rr      s
   z%Scope._create_new_propagation_contextc                 C   s   |   | _td| j dS )zt
        Creates a new propagation context and sets it as `_propagation_context`. Overwriting existing one.
        z,[Tracing] Create new propagation context: %sN)rr   ra   r   debugr{   r7   r7   r8   set_new_propagation_context   s
   
z!Scope.set_new_propagation_contextNc                 C   sD   |r|  |}|dur|| _td| j | jdu r |   dS dS )z
        Makes sure `_propagation_context` is set.
        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.
        Nz>[Tracing] Extracted propagation context from incoming data: %s)rx   ra   r   r|   r}   )rC   rb   rw   r7   r7   r8   re      s   

z"Scope.generate_propagation_contextc                 C   s6   | j du rdS |  }|dur| | j d< | j d S )z
        Returns the Dynamic Sampling Context from the Propagation Context.
        If not existing, creates a new one.
        Nrm   )ra   get_baggagerm   )rC   baggager7   r7   r8   get_dynamic_sampling_context	  s   

z"Scope.get_dynamic_sampling_contextc                 O   s\   | dd}|durt|jr| jdur| j S | jdu r dS d| jd | jd f }|S )z
        Returns the Sentry "sentry-trace" header (aka the traceparent) from the
        currently active span or the scopes Propagation Context.
        clientNz%s-%srn   ro   )popr   optionsspanZto_traceparentra   )rC   rD   rE   r   traceparentr7   r7   r8   get_traceparent  s   


zScope.get_traceparentc                 O   sf   | dd }|d urt|jr| jd ur| j S | jd u r d S | jd}|d u r/t| S t|S )Nr   rm   )	r   r   r   r   Z
to_baggagera   rk   r   Zfrom_options)rC   rD   rE   r   rm   r7   r7   r8   r~   3  s   



zScope.get_baggagec                 C   s6   | j du rdS | j d | j d | j d |  d}|S )zR
        Returns the Sentry "trace" context from the Propagation Context.
        Nrn   ro   rz   ry   )ra   r   )rC   Ztrace_contextr7   r7   r8   get_trace_contextJ  s   
zScope.get_trace_contextc                 O   s~   | dd}|durtd | dd}d}| j|d}|dur)|dt|f 7 }| j|d}|dur=|dt| f 7 }|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   rh   r   z<meta name="%s" content="%s">)r   r   warningr   r   r~   r   	serialize)rC   rD   rE   r   r   metaZsentry_tracer   r7   r7   r8   trace_propagation_meta[  s(   zScope.trace_propagation_metac                 c   sX    | j dur(|  }|durt|fV  |  }|dur*t| }t|fV  dS dS dS )zz
        Creates a generator which returns the `sentry-trace` and `baggage` headers from the Propagation Context.
        N)ra   r   r   r   r   r   r   )rC   r   Zdscr   r7   r7   r8   iter_headers{  s   

zScope.iter_headersc                 o   s    | dd}| dd}|o|jd }|sdS |p| j}|r4t|jr4|dur4| D ]}|V  q,dS |  D ]}|V  q8dS )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.
        r   Nr   propagate_traces)r   r   r   r   r   )rC   rD   rE   r   r   r   headerr7   r7   r8   iter_trace_propagation_headers  s   
z$Scope.iter_trace_propagation_headersc                 C   sf   d| _ d| _d| _i | _d| _i | _i | _i | _g | _| 	  d| _
d| _d| _d| _d| _d| _dS )zClears the entire scope.NT)rP   rR   rS   rT   rU   rV   rW   rX   r^   clear_breadcrumbsrB   r\   r]   r_   r`   ra   r{   r7   r7   r8   rc     s    
zScope.clearc                 C   s   t d || _dS )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   rP   rC   valuer7   r7   r8   level  s   
zScope.levelc                 C   
   || _ dS )zX
        Sets the level for the scope.

        :param value: The level to set.
        NrP   r   r7   r7   r8   	set_level  s   
zScope.set_levelc                 C   r   )z0When set this overrides the default fingerprint.N)rR   r   r7   r7   r8   fingerprint     
zScope.fingerprintc                 C   s&   | j du rdS | j jdu rdS | j jS )z8Return the transaction (root span) in the scope, if any.N)r\   containing_transactionr{   r7   r7   r8   transaction  s
   
zScope.transactionc                 C   s4   t d || _| jr| jjr|| jj_dS dS dS )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   rS   r\   r   namer   r7   r7   r8   r     s   c                 C   sB   || _ | jr| jjr|| jj_|r|| jj_|r|| jd< dS dS )z?Set the transaction name and optionally the transaction source.sourceN)rS   r\   r   r   r   rT   )rC   r   r   r7   r7   r8   set_transaction_name  s   

zScope.set_transaction_namec                 C   s   |  | dS )zPWhen set a specific user is bound to the scope. Deprecated in favor of set_user.N)set_userr   r7   r7   r8   user  s   z
Scope.userc                 C   s&   || _ | jdur| jj|d dS dS )zSets a user for the scope.N)r   )rU   r]   rq   r   r7   r7   r8   r     s   
zScope.set_userc                 C      | j S )z,Get/set current tracing span or transaction.)r\   r{   r7   r7   r8   r     s   z
Scope.spanc                 C   sD   || _ t|tr|}|jr|j| _|jr |j| jd< d S d S d S d S )Nr   )r\   
isinstancer   r   rS   r   rT   )rC   r   r   r7   r7   r8   r   %  s   
c                 C   r   r3   r`   r{   r7   r7   r8   profile2  s   zScope.profilec                 C   s
   || _ d S r3   r   )rC   r   r7   r7   r8   r   7  r   c                 C      || j |< dS )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)rV   rC   keyr   r7   r7   r8   set_tag=     	zScope.set_tagc                 C      | j |d dS )zX
        Removes a specific tag.

        :param key: Key of the tag to remove.
        N)rV   r   rC   r   r7   r7   r8   
remove_tagH  s   zScope.remove_tagc                 C   r   )zG
        Binds a context at a certain key to a specific value.
        N)rW   r   r7   r7   r8   set_contextQ  r   zScope.set_contextc                 C   r   )zRemoves a context.N)rW   r   r   r7   r7   r8   remove_context\     zScope.remove_contextc                 C   r   )z&Sets an extra key to a specific value.N)rX   r   r7   r7   r8   	set_extrac  s   zScope.set_extrac                 C   r   )zRemoves a specific extra key.N)rX   r   r   r7   r7   r8   remove_extral  r   zScope.remove_extrac                 C   s   t  | _dS )zClears breadcrumb buffer.N)r   rY   r{   r7   r7   r8   r   s  s   zScope.clear_breadcrumbsFc              	   C   s   | j t|||||d dS )z)Adds an attachment to future events sent.)bytespathfilenamecontent_typeadd_to_transactionsN)r^   r5   r   )rC   r   r   r   r   r   r7   r7   r8   add_attachmentx  s   
zScope.add_attachmentc                 K   s   | dd}|du rdS |jd}|jd}t|pd}|| |s'dS t|p+d}|ddu r9t |d< |ddu rDd|d< |durN|||}n|}|dur[| j| nt	d	| t
| j|krv| j  t
| j|kshdS dS )
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.
        r   Nbefore_breadcrumbmax_breadcrumbsr7   	timestamptypedefaultz)before breadcrumb dropped breadcrumb (%s))r   r   rk   dictrq   r   rY   r5   r   infolenpopleft)rC   ZcrumbhintrE   r   r   r   Z	new_crumbr7   r7   r8   add_breadcrumb  s.   



zScope.add_breadcrumbc                 K   s   | dd}| dd}|o|jd }||krt S | di }|du r1|d| tdi |}| |jd}|| |j|d t	||d}	|	j|d |j
re|o\|jd	 d
p^d}
|j|
d |S )a  
        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.

        For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Transaction`.
        hubNr   instrumentercustom_sampling_context)Ztransaction_contextparent_sampled)sampling_context)r   Z_experiments	max_spansi  )maxlenr7   )r   r   r   
setdefaultr   to_jsonr   rq   Z_set_initial_sampling_decisionr   Zsampledrk   Zinit_span_recorder)rC   r   r   rE   r   r   configuration_instrumenterr   r   r   r   r7   r7   r8   start_transaction  s.   
zScope.start_transactionc                 K   s  | dd}|o|jd }||krt S t|tsd|v rJd}t|tr2t| | j|fi |S d|v rJt| |d}| jdd|i|S |durWd}t| |S |d | j	}|durm|j
di |}	|	S d|vr|  }
|
r~|
d	d
 nd}|dur||d< tdi |S )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`.
        r   Nr   r   zcDeprecated: use start_transaction to start transactions and Transaction.start_child to start spans.r   z]Deprecated: passing a span into `start_span` is deprecated and will be removed in the future.rn   -r   r7   )rk   r   r   r   r   r   r   r   r   r   Zstart_childr   splitr   )rC   r   r   rE   r   r   deprecation_msgr   Zactive_spanZnew_child_spanr   rn   r7   r7   r8   
start_span  s:   





zScope.start_spanc                 C   s$   |  | tjt||||d}|S )ze
        Sets the propagation context from environment or headers and returns a transaction.
        )opr   r   )re   r   Zcontinue_from_headersr   )rC   Zenviron_or_headersr   r   r   r   r7   r7   r8   continue_trace;  s   
zScope.continue_tracec                 K   s(   |du rdS t | ||}|j|||dS )a  
        Captures an event.

        Merges given scope data and calls :py:meth:`sentry_sdk.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 client: The client to use for sending the event to Sentry.

        :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.capture_event`).
        N)eventr   scope)rN   capture_event)rC   r   r   r   r   rM   r7   r7   r8   r   K  s   zScope.capture_eventc                 K   s:   |du rdS |du rd}||d}| j |f||d|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 client: The client to use for sending the event to Sentry.

        :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.capture_event`).
        Nr   )messager   )r   r   )r   )rC   r   r   r   r   rM   r   r7   r7   r8   capture_messageh  s   zScope.capture_messagec                 K   sx   |du rdS |durt |}nt }t||jd\}}z| j|f|||d|W S  ty;   | t  Y dS w )a  Captures an exception.

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

        :param client: The client to use for sending the event to Sentry.

        :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.capture_event`).
        N)Zclient_options)r   r   r   )r   sysexc_infor   r   r   	Exception_capture_internal_exception)rC   errorr   r   rM   r   r   r   r7   r7   r8   capture_exception  s$   
zScope.capture_exceptionc                 C   s   t jd|d dS )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)r   N)r   r   )rC   r   r7   r7   r8   r     s   
z!Scope._capture_internal_exceptionc                 O   sX   | dd}| dd}| j|d t|r|jd nd|r"|jd nd| j|d| _dS )	zStarts a new session.r   Nsession_modeZapplicationr   releaseenvironment)r   r   r   r   )r   end_sessionr   r   rU   r]   )rC   rD   rE   r   r   r7   r7   r8   start_session  s   zScope.start_sessionc                 O   sF   | dd}| j}d| _|dur|  |dur!|| dS dS dS )z)Ends the current session if there is one.r   N)r   r]   closeZcapture_session)rC   rD   rE   r   sessionr7   r7   r8   r     s   zScope.end_sessionc                 O   s"   | dd}| j|d d| _dS )zStops automatic session tracking.

        This temporarily session tracking for the current scope when called.
        To resume session tracking call `resume_auto_session_tracking`.
        r   Nr   F)r   r   r_   )rC   rD   rE   r   r7   r7   r8   stop_auto_session_tracking  s   
z Scope.stop_auto_session_trackingc                 C   s
   d| _ dS )zResumes automatic session tracking for the current scope if
        disabled earlier.  This requires that generally automatic session
        tracking is enabled.
        N)r_   r{   r7   r7   r8   resume_auto_session_tracking  s   
z"Scope.resume_auto_session_trackingc                 C   s8   t | jdkrtd| j | jdd= | j| dS )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   rZ   r   r   r5   )rC   funcr7   r7   r8   add_event_processor  s   zScope.add_event_processorc                    s.   |dur| | fdd}| j | dS )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                    s<   z	t |d  }W n ty   d}Y nw |r| |S | S )N   F)r   r   )r   r   Zis_instZcls_Z	real_funcr7   r8   r     s   
z'Scope.add_error_processor.<locals>.func)r[   r5   )rC   r   clsr7   r   r8   add_error_processor  s
   
zScope.add_error_processorc                 C   s   | j d ur| j |d< d S d S )Nr   r   rC   r   r   r   r7   r7   r8   _apply_level_to_event  s   
zScope._apply_level_to_eventc                 C   s    | di  dg | j d S )NZbreadcrumbsvalues)r   extendrY   r   r7   r7   r8   _apply_breadcrumbs_to_event  s   z!Scope._apply_breadcrumbs_to_eventc                 C   .   | dd u r| jd ur| j|d< d S d S d S )Nr   )rk   rU   r   r7   r7   r8   _apply_user_to_event$     zScope._apply_user_to_eventc                 C   r   )Nr   )rk   rS   r   r7   r7   r8    _apply_transaction_name_to_event)  r   z&Scope._apply_transaction_name_to_eventc                 C   r   )NZtransaction_info)rk   rT   r   r7   r7   r8    _apply_transaction_info_to_event.  r   z&Scope._apply_transaction_info_to_eventc                 C   r   )Nr   )rk   rR   r   r7   r7   r8   _apply_fingerprint_to_event3  r   z!Scope._apply_fingerprint_to_eventc                 C   "   | j r|di | j  d S d S )Nextra)rX   r   rq   r   r7   r7   r8   _apply_extra_to_event8     zScope._apply_extra_to_eventc                 C   r   )Ntags)rV   r   rq   r   r7   r7   r8   _apply_tags_to_event=  r   zScope._apply_tags_to_eventc              	   C   s   | j r|di | j  |di }|dd u r1t|r+| jd ur+| j |d< n|  |d< z
|d d d }W n ttfyH   d }Y nw |d urUd|i|d< d S d S )Ncontextstracerm   	replay_idZreplay)	rW   r   rq   rk   r   r\   r   KeyErrorrH   )rC   r   r   r   r   r  r7   r7   r8   _apply_contexts_to_eventB  s    zScope._apply_contexts_to_eventc              	   C   s  | d}|dk}|dk}| dpg }| jD ]}|r|jr#|| q||d< | ||| |r?d|di  di i|d< |sr| ||| | ||| | ||| | 	||| | 
||| | ||| | ||| |s}|s}| ||| dd }	| d	}
|
d
ur| jD ]}|||
}|d
u r|	|d  S |}q|stt| jD ])}|}t  |||}W d
   n1 sw   Y  |d
u r|	|d  S |}q|S )zBApplies the information contained on the scope to the given event.r   r   Zcheck_inattachmentsr  r   c                 S   s   t d||  d S )Nz%s (%s) dropped event)r   r   )causetyr7   r7   r8   _drop  s   z#Scope.apply_to_event.<locals>._dropr   Nzerror processorzevent processor)rk   r^   r   r5   r  r   r   r   r   r   r   r   r   r   r[   r   r4   rZ   r   )rC   r   r   r   r  Zis_transactionZis_check_inZattachments_to_send
attachmentr  r   Zerror_processorZ	new_eventZevent_processorr7   r7   r8   apply_to_event[  sV   
	





zScope.apply_to_eventc                 C   s   |j dur	|j | _ |jdur|j| _|jdur|j| _|jdur'| j|j |jdur0|j| _|jr:| j|j |jrD| j|j |jrN| j|j |j	rX| j	
|j	 |jr_|j| _|jri| j
|j |jrp|j| _|jry|j| _dS dS )z+Update the scope with another scope's data.N)rP   rR   rS   rT   rq   rU   rV   rW   rX   rY   r   r\   r^   r`   ra   )rC   r   r7   r7   r8   rJ     s6   




zScope.update_from_scopec                 C   sn   |dur|| _ |dur|| _|dur| j| |dur"| j| |dur,| j| |dur5|| _dS dS )zUpdate the scope's attributes.N)rP   rU   rX   rq   rW   rV   rR   )rC   r   r   extrasr   r   r   r7   r7   r8   rK     s   
zScope.update_from_kwargsc                 C   s   t | 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| j|_| j|_|S r3   )object__new__	__class__rP   rQ   rR   rS   r   rT   rU   rV   rW   rX   r   rY   listrZ   r[   ra   rB   r\   r]   r_   r^   r`   )rC   rvr7   r7   r8   __copy__  s*   zScope.__copy__c                 C   s   d| j jtt| | jf S )Nz<%s id=%s name=%s>)r  __name__ru   idrQ   r{   r7   r7   r8   __repr__  s
   
zScope.__repr__r3   )NNNNF)NN)NNN)NNNNNN)Fr  
__module____qualname__r>   	__slots__rg   rd   rx   rr   r}   re   r   r   r~   r   r   r   r   rc   rA   r   r   r   r=   r   setterr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ZSENTRYr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rG   r
  rJ   rK   r  r  r7   r7   r7   r8   rO   w   s    
	
 
	








		

+
A
D


#$
F 
rO   )Hr   collectionsr   	itertoolsr   ri   r   rs   Zsentry_sdk.attachmentsr   Zsentry_sdk._compatr   Zsentry_sdk.constsr   r   Zsentry_sdk._functoolsr
   Zsentry_sdk.profilerr   Zsentry_sdk.sessionr   Zsentry_sdk.tracing_utilsr   r   r   r   Zsentry_sdk.tracingr   r   r   r   r   Zsentry_sdk._typesr   Zsentry_sdk.utilsr   r   r   r   collections.abcr   typingr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   Z
sentry_sdkr0   r2   r4   r9   rA   rG   rN   r  rO   r7   r7   r7   r8   <module>   sN    ,