o
    #if
r                     @   s  d dl Z d dlZd dlZd dl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 d dlmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d d	lmZ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/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8 e8rd dl9m:Z: d dl9m;Z; d dl9m<Z< d dl9m=Z= d dl9m>Z> d dl9m?Z? d dl9m@Z@ d dl7mAZAmBZB d dl%mCZC d dlDmEZE d dlFmGZG d dlHmIZI d d lmJZJ e(d!ZKd"e#d#e#d$gd%ZLd&d' ZMzeNZOW n ePy   eQZOY nw G d(d) d)ZRG d*d+ d+eRZSG d,d- d-eRZTd dl7m8Z8 e8rOG d.d/ d/e$e<eUe:f ZVG d0d1 d1e$eTZWdS d2d3  ZVd4d3  ZWdS )5    N)Mapping)datetimetimezone)import_module)PY37check_uwsgi_thread_support)
capture_internal_exceptionscurrent_stacktracedisable_capture_eventformat_timestampget_sdk_nameget_type_nameget_default_releasehandle_in_app	is_geventlogger)	serialize)trace)HttpTransportmake_transport)DEFAULT_MAX_VALUE_LENGTHDEFAULT_OPTIONSINSTRUMENTERVERSIONClientConstructor)_DEFAULT_INTEGRATIONSsetup_integrations)
ContextVar)SessionFlusher)Envelope)has_profiling_enabledProfilesetup_profiler)EventScrubber)Monitor)setup_spotlight)TYPE_CHECKING)Any)Callable)Dict)Optional)Sequence)Type)Union)EventHint)IntegrationMetricsAggregator)Scope)Session)	Transportclient_init_debugzsentry.pythonzpypi:sentry-sdk)nameversion)r7   r8   packagesc                  O   s  | rt | d 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rB|dd u rB||d< | D ]\}}||vrUtd|f |||< qF|d d u rht	j
d|d< |d d u rst |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 rt |d< |d rt |d tstd d |d< |S )Nr      z+Only single positional argument is expecteddsnz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socket_optionszxIgnoring socket_options because of unexpected format. See urllib3.HTTPConnection.socket_options for the expected format.)
isinstancebytesstrlen	TypeErrordictr   getitemsosenvironr   lowerhasattrsocketrH   r   SENTRYgetcwd	Exceptionr#   listr   warning)argskwargsr;   rvoptionskeyvaluerJ    rh   J/var/www/html/corbot_env/lib/python3.10/site-packages/sentry_sdk/client.py_get_optionsF   sV   "



rj   c                   @   s~   e Zd ZdZdddZdd Zdd Ze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dd ZdS )
BaseClientzp
    .. versionadded:: 2.0.0

    The basic definition of a client that is used for sending data to Sentry.
    Nc                 C   s(   |d ur|nt | _d | _d | _d | _d S N)r   re   	transportmonitormetrics_aggregator)selfre   rh   rh   ri   __init__   s
   
zBaseClient.__init__c                 O   s   di iS Nre   rh   rp   rb   rc   rh   rh   ri   __getstate__   s   zBaseClient.__getstate__c                 O      d S rl   rh   rs   rh   rh   ri   __setstate__      zBaseClient.__setstate__c                 C   ru   rl   rh   rp   rh   rh   ri   r;      s   zBaseClient.dsnc                 C      dS )NFrh   rx   rh   rh   ri   should_send_default_pii   rw   z"BaseClient.should_send_default_piic                 C   ry   )u
        .. versionadded:: 2.0.0

        Returns whether the client is active (able to send data to Sentry)
        Frh   rx   rh   rh   ri   	is_active      zBaseClient.is_activec                 O   ru   rl   rh   rs   rh   rh   ri   capture_event   rw   zBaseClient.capture_eventc                 O   ru   rl   rh   rs   rh   rh   ri   capture_session   rw   zBaseClient.capture_sessionc                 O   ru   rl   rh   rs   rh   rh   ri   get_integration   rw   zBaseClient.get_integrationc                 O   ru   rl   rh   rs   rh   rh   ri   close   rw   zBaseClient.closec                 O   ru   rl   rh   rs   rh   rh   ri   flush   rw   zBaseClient.flushc                 C      | S rl   rh   rx   rh   rh   ri   	__enter__   rw   zBaseClient.__enter__c                 C   ru   rl   rh   rp   exc_type	exc_valuetbrh   rh   ri   __exit__   rw   zBaseClient.__exit__rl   )__name__
__module____qualname____doc__rq   rt   rv   propertyr;   rz   r|   r~   r   r   r   r   r   r   rh   rh   rh   ri   rk      s     


	rk   c                   @   s   e Zd ZdZdS )NonRecordingClientz
    .. versionadded:: 2.0.0

    A client that does not send any events to Sentry. This is used as a fallback when the Sentry SDK is not yet initialized.
    N)r   r   r   r   rh   rh   rh   ri   r      s    r   c                       s   e Zd ZdZ f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dd Z	d+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%d&Zd'd( Zd)d* Z  ZS )-_ClientaI  
    The 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.

    Alias of :py:class:`sentry_sdk.Client`. (Was created for better intelisense support)
    c                    s(   t t| jt|i |d |   d S )Nre   )superr   rq   get_options
_init_implrs   	__class__rh   ri   rq      s   z_Client.__init__c                 C   s
   d| j iS rr   r   rx   rh   rh   ri   rt      s   
z_Client.__getstate__c                 C   s   |d | _ |   d S rr   )re   r   )rp   staterh   rh   ri   rv      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.r:   zEnabled tracing for %szWCan not enable tracing for '%s'. (%s) Please check your `functions_to_trace` parameter.)rsplitr   getattrsetattrr   r   rA   module_not_found_errortype__dict__staticmethodclassmethodr_   ra   )rp   functions_to_tracefunction
class_namefunction_qualnamemodule_namefunction_name
module_objfunction_obj	class_objfunction_typetraced_functionerh   rh   ri   _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d	rbt  pFt}|r]d
dlm} ||t|dd	d _
ntd d} jd |vrrtd| jd ddrt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   js j
st! jst% jt&rt'  d S d S )NFc                    s    j d ur j |  d S d S rl   )rm   capture_envelope)enveloperx   rh   ri   _capture_envelope3  s   
z-_Client._init_impl.<locals>._capture_enveloperA   enable_backpressure_handling)capture_func_experimentsenable_metricsTr   r1   metric_code_locations)r   enable_code_locationsz:Metrics not supported on Python 3.6 and lower with gevent.)alwaysneversmallmediummax_request_body_sizez:Invalid value for max_request_body_size. Must be one of {}otel_powered_performancezA[OTel] Enabling experimental OTel-powered performance monitoring.rI   zJsentry_sdk.integrations.opentelemetry.integration.OpenTelemetryIntegrationintegrationsdefault_integrationsauto_enabling_integrations)with_defaultswith_auto_enabling_integrations	spotlightr7   zSetting SDK name to '%s'zCan not set up profiler. (%s)r   )(_client_init_debugrV   setre   r   rm   rn   r$   r   session_flusherro   r   r   sentry_sdk.metricsr2   boolr   info
ValueErrorformatrA   r   OTELr   appendr   r   r   r%   r   r`   keysSDK_INFOr    r"   r_   r   rP   r   r   )	rp   	old_debugr   experimentsmetrics_supportedr2   r   sdk_namer   rh   rx   ri   r   /  s   






z_Client._init_implc                 C   ry   )r{   Trh   rx   rh   rh   ri   r|     r}   z_Client.is_activec                 C   s   | j ddS )z
        .. versionadded:: 2.0.0

        Returns whether the client should send default PII (Personally Identifiable Information) data to Sentry.
        send_default_piiF)re   rV   rx   rh   rh   ri   rz     s   z_Client.should_send_default_piic                 C   s
   | j d S )z%Returns the configured DSN as string.r;   r   rx   rh   rh   ri   r;     s   
z_Client.dsnc                 C   s  | dd u rttj|d< |d ur9| ddk}|||| j}|d u r7| jr5| jjd|r1dndd d S |}| jd rvd|vrvd	|vrvd
|vrvt	 ! dt
| j dd| j dtddddgi|d
< W d    n1 sqw   Y  dD ]}| |d u r| j| d urt| j|  ||< qx| 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r<|d ur<| ddkr<d }
t	  |	||pi }
W d    n	1 sw   Y  |
d u r:td | jr:| jjddd |
}| jd  }|d ur|d ur| ddkrd }
t	  |||p_i }
W d    n	1 slw   Y  |
d u rtd! | jr| jjddd |
}|S )"N	timestampr   transactionevent_processorerrordata_categoryattach_stacktrace	exception
stacktracethreadsvaluesinclude_local_variablesTmax_value_length)r   r   F)r   crashedcurrent)r=   r>   rG   distsdkr   platformpythonin_app_excludein_app_includerJ   rN   r   r   )r   r   before_sendzbefore send dropped eventbefore_send_transactionz%before send transaction dropped event)rV   r   nowr   utcapply_to_eventre   rm   record_lost_eventr   r	   r   rR   striprU   r   sortedr   r   r   scrub_eventr   r   r   )rp   eventhintscopeis_transactionevent_rf   sdk_inforN   r   	new_eventr   rh   rh   ri   _prepare_event  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)rV   r   r   re   rP   rR   
issubclass)rp   r   r   r   r   error_type_nameerror_full_nameignored_errorrh   rh   ri   _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 )Nr   r   TF)rV   _should_capturer  )rp   r   r   r   r   ignoring_prevents_recursionignored_by_config_optionrh   rh   ri   r  1  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_raterM   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)re   rV   callabler   random	NameErrorr   ra   rT   reprrm   r   )rp   r   r   r  r  not_in_sample_rate	parameterverbrh   rh   ri   _should_sample_errorG  s>   
z_Client._should_sample_errorc                 C   s   d}d}d }| dpi  d}|r.d}|D ]}| d}t|tr-| ddu r-d} nq| d}	|jd u r^| dp>i  d	}
t|
trI|
ni }| D ]\}}| d
kr]|} nqO|j|rddnd |	||j|pl| d d S )NFr   r   T	mechanismhandleduserrequestheadersz
user-agentr   )statusr  
user_agenterrors)	rV   rP   r   r  rU   rW   rZ   updater  )rp   sessionr   r   erroredr  
exceptionsr   r  r  r  headers_dictkvrh   rh   ri   _update_session_from_eventw  s6   




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 |d	}
|d
i dpyi }|di }|d tttjd}|r||d< t|d}|rt|tr|||| j || n|	r|| n|| |
pdD ]	}||  q| jr| j| | 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 :py:class:`sentry_sdk.Scope` to apply to events.

        :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_idrh   profiler   r   check_inattachmentscontextsr   dynamic_sampling_context)r!  sent_at)r  )r
   rV   rU   uuiduuid4hexr  popr   _sessionr   r  r   r   r   r   r   r   rP   r!   add_profileto_jsonre   add_transactionadd_checkin	add_eventadd_itemto_envelope_itemr   r   rm   )rp   r   r   r   r!  r"  	event_optr  r   
is_checkinr$  trace_contextr&  r  r   
attachmentrh   rh   ri   r~     sd   







z_Client.capture_eventc                 C   s$   |j s
td d S | j| d S )Nz3Discarded session update because of missing release)r=   r   r   r   add_session)rp   r  rh   rh   ri   r     s   z_Client.capture_sessionc                 C   s6   t |tr|}n|jdur|j}ntd| j|S )zReturns the integration for this client by name or class.
        If the client does not have that integration then `None` is returned.
        NzIntegration has no name)rP   rR   
identifierr   r   rV   )rp   name_or_classintegration_namerh   rh   ri   r     s   

z_Client.get_integrationc                 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)rm   r   r   killro   rn   rp   r=  r>  rh   rh   ri   r     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<  )rm   re   r   r   ro   r@  rh   rh   ri   r   "  s   




z_Client.flushc                 C   r   rl   rh   rx   rh   rh   ri   r   7  rw   z_Client.__enter__c                 C   s   |    d S rl   )r   r   rh   rh   ri   r   ;  s   z_Client.__exit__rl   )NN)r   r   r   r   rq   rt   rv   r   r   r|   rz   r   r;   r   r  r  r  r   r~   r   r   r   r   r   r   __classcell__rh   rh   r   ri   r      s<    	4^		
v
0(
Y	

r   c                   @      e Zd ZdS )r   Nr   r   r   rh   rh   rh   ri   r   I      r   c                   @   rC  )ClientNrD  rh   rh   rh   ri   rF  L  rE  rF  c                   C      t S rl   )rj   rh   rh   rh   ri   <lambda>U      rH  c                   C   rG  rl   )r   rh   rh   rh   ri   rH  V  rI  )XrX   r(  r
  r\   collections.abcr   r   r   	importlibr   sentry_sdk._compatr   r   sentry_sdk.utilsr   r	   r
   r   r   r   r   r   r   r   sentry_sdk.serializerr   sentry_sdk.tracingr   sentry_sdk.transportr   r   sentry_sdk.constsr   r   r   r   r   sentry_sdk.integrationsr   r   r   sentry_sdk.sessionsr   sentry_sdk.enveloper   sentry_sdk.profilerr    r!   r"   sentry_sdk.scrubberr#   sentry_sdk.monitorr$   sentry_sdk.spotlightr%   sentry_sdk._typesr&   typingr'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r   r2   sentry_sdk.scoper3   sentry_sdk.sessionr4   r5   r   r   rj   ModuleNotFoundErrorr   r_   ImportErrorrk   r   r   rR   r   rF  rh   rh   rh   ri   <module>   sx    0
CH
    a
	