o
    :lif                     @   s>  d dl mZ d dlZd dlZd dlZd dl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mZmZmZmZ d dlmZ d dlmZmZ d dlmZ d dlmZmZmZm Z m!Z! d d	l"m#Z#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/m0Z0 d dl1m2Z2 d dl3m4Z4 e4rd dl5m6Z6 d dl5m7Z7 d dl5m8Z8 d dl5m9Z9 d dl5m:Z: d dl;m<Z< d dl3m=Z=m>Z> d dl?m@Z@ e%dZAde de dgdZBdd  ZCzeDZEW n eFy   eGZEY nw G d!d" d"eHZId dl3m4Z4 e4rG d#d$ d$e!e8eJe6f ZKG d%d& d&e!eIZLdS d'd(  ZKd)d(  ZLdS )*    )import_moduleN)datetime_utcnowstring_types	text_type	iteritems)	capture_internal_exceptionscurrent_stacktracedisable_capture_eventformat_timestampget_sdk_nameget_type_nameget_default_releasehandle_in_applogger)	serialize)tracehas_tracing_enabled)make_transport)DEFAULT_MAX_VALUE_LENGTHDEFAULT_OPTIONSINSTRUMENTERVERSIONClientConstructor)_DEFAULT_INTEGRATIONSsetup_integrations)
ContextVar)SessionFlusher)Envelope)has_profiling_enabledsetup_profiler)EventScrubber)Monitor)setup_spotlight)TYPE_CHECKING)Any)Callable)Dict)Optional)Sequence)Scope)EventHint)Sessionclient_init_debugzsentry.pythonzpypi:sentry-sdk)nameversion)r.   r/   packagesc            	      O   s  | rt | d tttfs| d d u r| d }| dd  } nd }t| dkr)tdtt}t| i |}|d urC|dd u rC||d< t	|D ]3\}}||vrv|dkr_d}t
| ||d< qG|dkrod	}t
| ||d
< qGtd|f |||< qG|d d u rtjd|d< |d d u rt |d< |d d u rtjdpd|d< |d d u rtjdd dv |d< |d d u rttdrt |d< |d d u rtj|d< |d d u rzt }W n ty   d }Y nw ||d< |d du r|d d u rd|d< |d d u rt |d< |S )Nr      z+Only single positional argument is expecteddsnwith_localszDeprecated: The option 'with_locals' was renamed to 'include_local_variables'. Please use 'include_local_variables'. The option 'with_locals' will be removed in the future.include_local_variablesrequest_bodieszDeprecated: The option 'request_bodies' was renamed to 'max_request_body_size'. Please use 'max_request_body_size'. The option 'request_bodies' will be removed in the future.max_request_body_sizezUnknown option %r
SENTRY_DSNreleaseenvironmentSENTRY_ENVIRONMENT
productiondebugSENTRY_DEBUGFalse)true1tserver_namegethostnameinstrumenterproject_rootenable_tracingTtraces_sample_rate      ?event_scrubber)
isinstancer   bytesstrlen	TypeErrordictr   getr   r   warningosenvironr   lowerhasattrsocketrC   r   SENTRYgetcwd	Exceptionr    )	argskwargsr2   rvoptionskeyvaluemsgrE    ra   a/var/www/html/tatsat2dev/dashboard-backend/venv/lib/python3.10/site-packages/sentry_sdk/client.py_get_options>   sd   $





rc   c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Ze	dd Z
dd Zdd Z	d%ddZdd Zdd Z		d&ddZdd Z		d&ddZ		d&dd Zd!d" Zd#d$ ZdS )'_ClientzThe client is internally responsible for capturing the events and
    forwarding them to sentry through the configured transport.  It takes
    the client options as keyword arguments and optionally the DSN as first
    argument.
    c                 O   s   t |i || _|   d S N)get_optionsr]   
_init_impl)selfrZ   r[   ra   ra   rb   __init__   s   z_Client.__init__c                 C   s
   d| j iS Nr]   r]   rh   ra   ra   rb   __getstate__   s   
z_Client.__getstate__c                 C   s   |d | _ |   d S rj   )r]   rg   )rh   statera   ra   rb   __setstate__   s   
z_Client.__setstate__c                 C   sP  |D ]}d}|d }| dd\}}zt|}t||}t||t| td| W q ty   z?| dd\}}t|}t||}	t|	|}t|	j	| }
t|}|
t
tfv r^t
|}t|	|| t|||	 td| W n ty } ztd|| W Y d}~nd}~ww Y q ty } ztd|| W Y d}~qd}~ww dS )z
        Instruments the functions given in the list `functions_to_trace` with the `@sentry_sdk.tracing.trace` decorator.
        Nqualified_name.r1   zEnabled tracing for %szWCan not enable tracing for '%s'. (%s) Please check your `functions_to_trace` parameter.)rsplitr   getattrsetattrr   r   r<   module_not_found_errortype__dict__staticmethodclassmethodrY   rQ   )rh   functions_to_tracefunction
class_namefunction_qualnamemodule_namefunction_name
module_objfunction_obj	class_objfunction_typetraced_functionera   ra   rb   _setup_instrumentation   sP   


z_Client._setup_instrumentationc              
      s  t d} fdd}zt  jd  t j _d  _ jr+ jd r+t j _t|d _	d  _
 jdi }|drRd	d
lm} ||t|dd _
d} jd |vrbtd| jd ddr{td tj jd< td t jd  jd  jd d _d  _ jdrt j _tt j }|td< td| t jrzt j W n t y } ztd| W Y d }~nd }~ww W t | nt | w  ! jdg  d S )NFc                    s    j d ur j |  d S d S re   )	transportcapture_envelope)enveloperl   ra   rb   _capture_envelope   s   
z-_Client._init_impl.<locals>._capture_enveloper<   enable_backpressure_handling)capture_func_experimentsenable_metricsr   )MetricsAggregatormetric_code_locations)r   enable_code_locations)alwaysneversmallmediumr6   z:Invalid value for max_request_body_size. Must be one of {}otel_powered_performancezA[OTel] Enabling experimental OTel-powered performance monitoring.rD   zJsentry_sdk.integrations.opentelemetry.integration.OpenTelemetryIntegrationintegrationsdefault_integrationsauto_enabling_integrations)with_defaultswith_auto_enabling_integrations	spotlightr.   zSetting SDK name to '%s'zCan not set up profiler. (%s)rz   )"_client_init_debugrP   setr]   r   r   monitorr!   r   session_flushermetrics_aggregatorsentry_sdk.metricsr   bool
ValueErrorformatr   r<   r   OTELr   appendr   r   r   r"   r   listkeysSDK_INFOr   r   rY   r   )rh   	old_debugr   experimentsr   r6   sdk_namer   ra   rl   rb   rg      st   



z_Client._init_implc                 C   s
   | j d S )z%Returns the configured DSN as string.r2   rk   rl   ra   ra   rb   r2   -  s   
z_Client.dsnc                 C   s  | dd u rt |d< |d ur6| ddk}|||| j}|d u r4| jr2| jjd|r.dndd d S |}| jd rsd|vrsd	|vrsd
|vrst ! dt| j dd| j dtddddgi|d
< W d    n1 snw   Y  dD ]}| |d u r| j| d urt	| j| 
 ||< qu| dd u rtt}t| j |d< ||d< | dd u rd|d< t|| jd | jd | jd }|d ur| jd }|r| jd s|| |d urt|| j d| j dd}| jd }	|	d ur9|d ur9| ddkr9d }
t  |	||pi }
W d    n	1 sw   Y  |
d u r7td | jr7| jjddd |
}| jd  }|d ur|d ur| ddkrd }
t  |||p\i }
W d    n	1 siw   Y  |
d u rtd! | jr| jjddd |
}|S )"N	timestamprv   transactionevent_processorerrordata_categoryattach_stacktrace	exception
stacktracethreadsvaluesr4   Tmax_value_length)r4   r   F)r   crashedcurrent)r8   r9   rB   distsdkr   platformpythonin_app_excludein_app_includerE   rI   send_default_piir6   )r6   r   before_sendzbefore send dropped eventbefore_send_transactionz%before send transaction dropped event)rP   r   apply_to_eventr]   r   record_lost_eventr   r   r   r   striprO   r   sortedr   r   r   scrub_eventr   r   info)rh   eventhintscopeis_transactionevent_r^   sdk_inforI   r   	new_eventr   ra   ra   rb   _prepare_event3  s   
















z_Client._prepare_eventc                 C   s   | d}|d u rdS |d }t|d }d|d j|f }| jd D ]}t|tr6||ks2||kr5 dS q#t||r> dS q#dS )Nexc_infoFr   z%s.%signore_errorsT)rP   r   
__module__r]   rJ   r   
issubclass)rh   r   r   r   r   error_type_nameerror_full_nameignored_errorra   ra   rb   _is_ignored_error  s   


z_Client._is_ignored_errorNc                 C   sF   | ddk}|rdS |d uo|j }|rdS | ||}|r!dS dS )Nrv   r   TF)rP   _should_capturer   )rh   r   r   r   r   ignoring_prevents_recursionignored_by_config_optionra   ra   rb   r     s   z_Client._should_capturec              
   C   s   | j dd }t|r$t  |||}W d    n1 sw   Y  n| j d }z|dk o3t |k}W n0 tyE   td d}Y n! tye   t|rQdnd\}}td||t	|f  d}Y nw |ru| j
rs| j
jdd	d
 dS dS )Nerror_samplersample_raterH   zMThe provided error_sampler raised an error. Defaulting to sampling the event.F)r   returned)r   containszsThe provided %s %s an invalid value of %s. The value should be a float or a bool. Defaulting to sampling the event.r   r   T)r]   rP   callabler   random	NameErrorr   rQ   rN   reprr   r   )rh   r   r   r   r   not_in_sample_rate	parameterverbra   ra   rb   _should_sample_error  s>   
z_Client._should_sample_errorc                 C   s   d}d}d }| dpi  d}|r+d}|D ]}| d}|r*| ddu r*d} nq| d}	|jd u rT| dp;i  d	}
t|
pCi D ]\}}| d
krS|} nqE|j|rZdnd |	||j|pb| d d S )NFr   r   T	mechanismhandleduserrequestheadersz
user-agentr   )statusr   
user_agenterrors)rP   r   r   rT   updater   )rh   sessionr   r   erroredr   
exceptionsr   r   r   r   kvra   ra   rb   _update_session_from_event  s4   




z"_Client._update_session_from_eventc                 C   s  t drdS |du ri }|d}t|pd}|du r%t j |d< }| |||s.dS |dd}| |||}|du rAdS |rF|j	nd}|rP| 
|| |ddk}|ddk}	|sj|	sj| ||sjdS t| j}
|d	}|d
i dp~i }|di }|
p|p|	pt|pt| j}|r|d tt d}|r||d< t|d}|r|dur|||| j || n|	r|| n|| |pdD ]	}||  q| jr| j| | jdu rdS | j| |S | jdu rdS | j| |S )a>  Captures an 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 scope to use for determining whether this event
            should be captured.

        :returns: An event ID. May be `None` if there is no DSN set or of if the SDK decided to discard the event for other reasons. In such situations setting `debug=True` on `init()` may help.
        FNevent_idra   profilerv   r   check_inattachmentscontextsr   dynamic_sampling_context)r   sent_at)r   )r	   rP   rO   uuiduuid4hexr   popr   _sessionr   r   r   r]   r   r   r
   r   r   add_profileto_jsonadd_transactionadd_checkin	add_eventadd_itemto_envelope_itemr   r   capture_event)rh   r   r   r   r   r   	event_optr   r   
is_checkintracing_enabledr   trace_contextr   should_use_envelope_endpointr   r   
attachmentra   ra   rb   r  )  s   







	
z_Client.capture_eventc                 C   s$   |j s
td d S | j| d S )Nz3Discarded session update because of missing release)r8   r   r   r   add_session)rh   r   ra   ra   rb   capture_session  s   z_Client.capture_sessionc                 C   s^   | j dur-| j||d | j  | jdur| j  | jr#| j  | j   d| _ dS dS )z
        Close the client and shut down the transport. Arguments have the same
        semantics as :py:meth:`Client.flush`.
        Ntimeoutcallback)r   flushr   killr   r   rh   r  r  ra   ra   rb   close  s   







z_Client.closec                 C   sR   | j dur'|du r| jd }| j  | jdur| j  | j j||d dS dS )a#  
        Wait for the current events to be sent.

        :param timeout: Wait for at most `timeout` seconds. If no `timeout` is provided, the `shutdown_timeout` option value is used.

        :param callback: Is invoked with the number of pending events and the configured timeout.
        Nshutdown_timeoutr  )r   r]   r   r  r   r  ra   ra   rb   r    s   




z_Client.flushc                 C   s   | S re   ra   rl   ra   ra   rb   	__enter__  s   z_Client.__enter__c                 C   s   |    d S re   )r  )rh   exc_type	exc_valuetbra   ra   rb   __exit__  s   z_Client.__exit__re   )NN)__name__r   __qualname____doc__ri   rm   ro   r   rg   propertyr2   r   r   r   r   r   r  r  r  r  r  r!  ra   ra   ra   rb   rd      s6    4L
v
0'
l

rd   c                   @      e Zd ZdS )rf   Nr"  r   r#  ra   ra   ra   rb   rf         rf   c                   @   r&  )ClientNr'  ra   ra   ra   rb   r)    r(  r)  c                   C      t S re   )rc   ra   ra   ra   rb   <lambda>      r+  c                   C   r*  re   )rd   ra   ra   ra   rb   r+    r,  )M	importlibr   rR   r   r   rV   sentry_sdk._compatr   r   r   r   sentry_sdk.utilsr   r   r	   r
   r   r   r   r   r   sentry_sdk.serializerr   sentry_sdk.tracingr   r   sentry_sdk.transportr   sentry_sdk.constsr   r   r   r   r   sentry_sdk.integrationsr   r   r   sentry_sdk.sessionsr   sentry_sdk.enveloper   sentry_sdk.profilerr   r   sentry_sdk.scrubberr    sentry_sdk.monitorr!   sentry_sdk.spotlightr"   sentry_sdk._typesr#   typingr$   r%   r&   r'   r(   sentry_sdk.scoper)   r*   r+   sentry_sdk.sessionr,   r   r   rc   ModuleNotFoundErrorru   rY   ImportErrorobjectrd   rL   rf   r)  ra   ra   ra   rb   <module>   sf    ,
Q    =
	