o
    ZhOo                     @   s  zd dl mZ W n ey   d dlmZ Y nw 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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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l0m1Z1 d dl2m3Z3m4Z4m5Z5 d dl6m7Z7 d dl8m9Z9 d dl:m;Z; d dl<m=Z= e=rd dl>m?Z? d dl>m@Z@ d dl>mAZA d dl>mBZB d dl>mCZC d dl>mDZD d dl>mEZE d dl*mFZF d dlGmHZH d dl<mIZImJZJ d dlKmLZL e-dZMde(d e(d!gd"ZNd#d$ ZOzePZQW n eRy   eZQY nw G d%d& d&eSZTd dl<m=Z= e=rHG d'd( d(e)eAeUe?f ZVG d)d* d*e)eTZWdS d+d,  ZVd-d,  ZWdS ).    )Mapping)import_moduleN)PY37datetime_utcnowstring_types	text_type	iteritems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has_tracing_enabled)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)Integration)Scope)EventHint)SessionZclient_init_debugzsentry.pythonzpypi:sentry-sdk)nameversion)r6   r7   packagesc            	      O   sF  | 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< |d r!t |d ts!t
d d |d< |S ) Nr      z+Only single positional argument is expecteddsnZ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_variablesZ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 %rZ
SENTRY_DSNreleaseenvironmentZSENTRY_ENVIRONMENT
productiondebugZSENTRY_DEBUGFalse)true1tserver_namegethostnameinstrumenterproject_rootZenable_tracingTZtraces_sample_rate      ?event_scrubbersocket_optionszxIgnoring socket_options because of unexpected format. See urllib3.HTTPConnection.socket_options for the expected format.)
isinstancer   bytesstrlen	TypeErrordictr   getr   r   warningosenvironr   lowerhasattrsocketrF   r   ZSENTRYgetcwd	Exceptionr&   list)	argskwargsr:   rvoptionskeyvaluemsgrH    rc   H/var/www/html/lang_env/lib/python3.10/site-packages/sentry_sdk/client.py_get_optionsN   sn   $





re   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 Z		d(dd Z		d(d!d"Zd#d$ Zd%d& ZdS ))_Clienta9  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:`Client`. (Was created for better intelisense support)
    c                 O   s   t |i || _|   d S N)get_optionsr_   
_init_impl)selfr\   r]   rc   rc   rd   __init__   s   z_Client.__init__c                 C   s
   d| j iS Nr_   r_   rj   rc   rc   rd   __getstate__   s   
z_Client.__getstate__c                 C   s   |d | _ |   d S rl   )r_   ri   )rj   staterc   rc   rd   __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.
        NZqualified_name.r9   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classmethodrZ   rS   )rj   functions_to_tracefunction
class_nameZfunction_qualnamemodule_nameZfunction_nameZ
module_objZfunction_objZ	class_objZfunction_typeZtraced_functionerc   rc   rd   _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 rg   )	transportcapture_envelope)envelopern   rc   rd   _capture_envelope   s   
z-_Client._init_impl.<locals>._capture_enveloper@   Zenable_backpressure_handling)capture_funcZ_experimentsZenable_metricsTr   )MetricsAggregatorZmetric_code_locations)r   Zenable_code_locationsz:Metrics not supported on Python 3.6 and lower with gevent.)alwaysneverZsmallZmediumr<   z:Invalid value for max_request_body_size. Must be one of {}Zotel_powered_performancezA[OTel] Enabling experimental OTel-powered performance monitoring.rG   zJsentry_sdk.integrations.opentelemetry.integration.OpenTelemetryIntegrationintegrationsZdefault_integrationsZauto_enabling_integrations)Zwith_defaultsZwith_auto_enabling_integrations	spotlightr6   zSetting SDK name to '%s'zCan not set up profiler. (%s)r{   )(_client_init_debugrR   setr_   r   r   monitorr'   r!   session_flushermetrics_aggregatorr   r   Zsentry_sdk.metricsr   boolr   info
ValueErrorformatr@   r   ZOTELr   appendr   r   r   r(   r   r[   keysSDK_INFOr#   r%   rZ   r   rL   r   r	   )	rj   Z	old_debugr   ZexperimentsZmetrics_supportedr   r<   Zsdk_namer   rc   rn   rd   ri      s   






z_Client._init_implc                 C   s
   | j d S )z%Returns the configured DSN as string.r:   rm   rn   rc   rc   rd   r:   W  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	timestamprw   transactionZevent_processorerrorZdata_categoryZattach_stacktrace	exception
stacktracethreadsvaluesr;   Tmax_value_length)r;   r   F)r   crashedcurrent)r=   r>   rE   distZsdkr   platformpythonZin_app_excludeZin_app_includerH   rJ   Zsend_default_piir<   )r<   r   before_sendzbefore send dropped eventbefore_send_transactionz%before send transaction dropped event)rR   r   Zapply_to_eventr_   r   record_lost_eventr
   r   r   r   striprQ   r   sortedr   r   r   Zscrub_eventr   r   r   )rj   eventhintscopeis_transactionZevent_r`   Zsdk_inforJ   r   Z	new_eventr   rc   rc   rd   _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)rR   r   
__module__r_   rL   r   
issubclass)rj   r   r   r   r   Zerror_type_nameZerror_full_nameZignored_errorrc   rc   rd   _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 )Nrw   r   TF)rR   _should_capturer   )rj   r   r   r   r   Zignoring_prevents_recursionZignored_by_config_optionrc   rc   rd   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_raterI   zMThe provided error_sampler raised an error. Defaulting to sampling the event.F)r   Z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_   rR   callabler
   random	NameErrorr   rS   rP   reprr   r   )rj   r   r   r   r   Znot_in_sample_rateZ	parameterZverbrc   rc   rd   _should_sample_error  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 rW| dp>i  d	}
t|
pFi D ]\}}| d
krV|} nqH|j|r]dnd |	||j|pe| d d S )NFr   r   T	mechanismZhandleduserrequestheadersz
user-agentr   )statusr   
user_agenterrors)rR   rL   r   r   r   rV   updater   )rj   sessionr   r   Zerroredr   
exceptionsr   r   r   r   kvrc   rc   rd   _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}|rt|t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 )am  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.
            The `scope` and `scope_kwargs` parameters are mutually exclusive.

        :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_idrc   profilerw   r   Zcheck_inattachmentsZcontextsr   dynamic_sampling_context)r   Zsent_at)r   )r   rR   rQ   uuiduuid4hexr   popr   _sessionr   r   r   r_   r   r   r   r   r"   rL   r$   Zadd_profileto_jsonZadd_transactionZadd_checkinZ	add_eventZadd_itemZto_envelope_itemr   r   capture_event)rj   r   r   r   r   r   Z	event_optr   r   Z
is_checkinZtracing_enabledr   Ztrace_contextr   Zshould_use_envelope_endpointr   r   
attachmentrc   rc   rd   r   S  s   








	
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   Zadd_session)rj   r   rc   rc   rd   capture_session  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)rL   rN   
identifierr   r   rR   )rj   Zname_or_classZintegration_namerc   rc   rd   get_integration  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)r   flushr   killr   r   rj   r   r   rc   rc   rd   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.
        NZshutdown_timeoutr   )r   r_   r   r   r   r   rc   rc   rd   r     s   




z_Client.flushc                 C   s   | S rg   rc   rn   rc   rc   rd   	__enter__  s   z_Client.__enter__c                 C   s   |    d S rg   )r   )rj   exc_type	exc_valuetbrc   rc   rd   __exit__  s   z_Client.__exit__rg   )NN)__name__r   __qualname____doc__rk   ro   rq   r   ri   propertyr:   r   r   r   r   r   r   r   r   r   r   r   r   rc   rc   rc   rd   rf      s8    4^
v
0'
l	

rf   c                   @      e Zd ZdS )rh   Nr   r   r   rc   rc   rc   rd   rh         rh   c                   @   r   )ClientNr   rc   rc   rc   rd   r     r   r   c                   C      t S rg   )re   rc   rc   rc   rd   <lambda>      r   c                   C   r   rg   )rf   rc   rc   rc   rd   r      r   )Xcollections.abcr   ImportErrorcollections	importlibr   rT   r   r   rX   Zsentry_sdk._compatr   r   r   r   r   r	   Zsentry_sdk.utilsr
   r   r   r   r   r   r   r   r   r   Zsentry_sdk.serializerr   Zsentry_sdk.tracingr   r   Zsentry_sdk.transportr   r   Zsentry_sdk.constsr   r   r   r   r   Zsentry_sdk.integrationsr   r   r    Zsentry_sdk.sessionsr!   Zsentry_sdk.enveloper"   Zsentry_sdk.profilerr#   r$   r%   Zsentry_sdk.scrubberr&   Zsentry_sdk.monitorr'   Zsentry_sdk.spotlightr(   Zsentry_sdk._typesr)   typingr*   r+   r,   r-   r.   r/   r0   r1   Zsentry_sdk.scoper2   r3   r4   Zsentry_sdk.sessionr5   r   r   re   ModuleNotFoundErrorrv   rZ   objectrf   rN   rh   r   rc   rc   rc   rd   <module>   sv     0
W    a
	