
    Yf
r                        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 e8rPd 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& ZM	 eNZO G d' d(      ZR G d) d*eR      ZS G d+ d,eR      ZTd dl7m8Z8 e8r G d- d.e$e<eUe:f         ZV G d/ d0e$eT      ZWy d1        ZV d2        ZWy# eP$ r eQZOY `w xY w)3    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)r8   r9   packagesc                     | r)t        | d   t        t        f      s| d   | d   }| dd  } nd }t        |       dkD  rt	        d      t        t              }t        | i |}||j                  d      ||d<   |j                         D ]  \  }}||vrt	        d|      |||<    |d   "t        j                  j                  d      |d<   |d   t               |d<   |d   &t        j                  j                  d	      xs d
|d<   |d   3t        j                  j                  dd      j                         dv |d<   |d   't        t        d      rt        j                         |d<   |d   t         j"                  |d<   |d   	 t        j$                         }||d<   |d   du r
|d   d|d<   |d   t)               |d<   |d   r-t        |d   t*              st-        j.                  d       d |d<   |S # t&        $ r d }Y iw xY w)Nr      z+Only single positional argument is expecteddsnzUnknown option 
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socketrJ   r   SENTRYgetcwd	Exceptionr$   listr   warning)argskwargsr=   rvoptionskeyvaluerL   s           Q/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/sentry_sdk/client.py_get_optionsrk   F   sJ   DGeS\2d1go1gABx
4y1}EFF	o	BD#F#G
7;;u-5mmo 
Ub=38993	 
%yJJNN<05		)}+-9	- JJNN+?@PL=	'{jjnn^W=CCE J
 
7 
- WV]%C"..0=	.!)00>	.!	 99;L *>	
t#+?(@(H#& 	
#,	
Jr2B/CT$J G	
  $I#  	 L	 s   G> >HHc                   j    e Zd ZdZddZd Zd Zed        Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zy)
BaseClientzp
    .. versionadded:: 2.0.0

    The basic definition of a client that is used for sending data to Sentry.
    Nc                 L    ||nt         | _        d | _        d | _        d | _        y N)r   rg   	transportmonitormetrics_aggregator)selfrg   s     rj   __init__zBaseClient.__init__   s-     *G 	 "&    c                 
    di iS Nrg    rs   rd   re   s      rj   __getstate__zBaseClient.__getstate__   s    2ru   c                      y ro   rx   ry   s      rj   __setstate__zBaseClient.__setstate__   s    ru   c                      y ro   rx   rs   s    rj   r=   zBaseClient.dsn   s     ru   c                      y)NFrx   r~   s    rj   should_send_default_piiz"BaseClient.should_send_default_pii   s    ru   c                      y)u
        .. versionadded:: 2.0.0

        Returns whether the client is active (able to send data to Sentry)
        Frx   r~   s    rj   	is_activezBaseClient.is_active   s     ru   c                      y ro   rx   ry   s      rj   capture_eventzBaseClient.capture_event       ru   c                      y ro   rx   ry   s      rj   capture_sessionzBaseClient.capture_session   r   ru   c                      y ro   rx   ry   s      rj   get_integrationzBaseClient.get_integration   r   ru   c                      y ro   rx   ry   s      rj   closezBaseClient.close   r   ru   c                      y ro   rx   ry   s      rj   flushzBaseClient.flush   r   ru   c                     | S ro   rx   r~   s    rj   	__enter__zBaseClient.__enter__       ru   c                      y ro   rx   rs   exc_type	exc_valuetbs       rj   __exit__zBaseClient.__exit__   r   ru   ro   )__name__
__module____qualname____doc__rt   rz   r|   propertyr=   r   r   r   r   r   r   r   r   r   rx   ru   rj   rm   rm      sW    '  ru   rm   c                       e Zd ZdZy)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   rx   ru   rj   r   r      s     	ru   r   c                        e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
ed	        Zd
 Zd Z	 ddZd Zd Z	 	 ddZd Zd Z	 	 ddZ	 	 ddZd Zd Z x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                 `    t         t        |   t        |i |       | j	                          y )Nrg   )superr   rt   get_options
_init_impl)rs   rd   re   	__class__s      rj   rt   z_Client.__init__   s)    gt%k4.J6.J%Kru   c                     d| j                   iS rw   r   r~   s    rj   rz   z_Client.__getstate__   s    4<<((ru   c                 8    |d   | _         | j                          y rw   )rg   r   )rs   states     rj   r|   z_Client.__setstate__   s    Y'ru   c                    |D ]b  }d}|d   }|j                  dd      \  }}	 t        |      }t        ||      }t        ||t	        |             t        j                  d|       d y# t        $ r 	 |j                  dd      \  }}t        |      }t        ||      }	t        |	|      }t        |	j                  |         }
t	        |      }|
t        t        fv rt        |      }t        |	||       t        |||	       t        j                  d|       n-# t        $ r!}t        j                  d||       Y d}~nd}~ww xY wY Et        $ r"}t        j                  d||       Y d}~jd}~ww xY w)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   rC   module_not_found_errortype__dict__staticmethodclassmethodra   rc   )rs   functions_to_tracefunction
class_namefunction_qualnamemodule_namefunction_name
module_objfunction_obj	class_objfunction_typetraced_functiones                rj   _setup_instrumentationz_Client._setup_instrumentation   sw   
 + -	HJ ()9 :):)A)A#q)I&K( +;7
&z=A
M53FG57HI-	 *  /:.@.@a.H+K!.{!;J '
J ?I#*9m#DL$(););M)J$KM&+L&9O${(CC*6*GI}oFJ
I>LL!9;LM  NNq)   m% sI   AA))	E23B$DE2	E!D=8E2=EE2E2E--E2c           	          t         j                  d      } fd}	 t         j                   j                  d          t	         j                         _        d  _         j
                  r) j                  d   rt         j
                         _        t        |       _	        d  _
         j                  j                  di       }|j                  dd      rYt                xs t        }|r/d	d
lm}  ||t        |j                  dd                   _
        nt!        j"                  d       d} j                  d   |vrt%        dj'                  |             j                  d   j                  dd      rGt!        j(                  d       t*        j,                   j                  d<   t/        j0                  d       t3         j                  d    j                  d    j                  d          _        d  _         j                  j                  d      rt9         j                         _        t;        t=         j4                  j?                                     }|t@        d<   t!        j(                  d|       tC         j                        r	 tE         j                         t         j                  |        jI                   j                  j                  dg               j                  s; j                  s/tC         j                        stK         j
                  tL              rtO                y y # tF        $ r }t!        j(                  d|       Y d }~d }~ww xY w# t         j                  |       w xY w)NFc                 V    j                   j                   j                  |        y y ro   )rp   capture_envelope)envelopers   s    rj   _capture_envelopez-_Client._init_impl.<locals>._capture_envelope3  s$    ~~)//9 *ru   rC   enable_backpressure_handling)capture_func_experimentsenable_metricsTr   r2   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.rK   zJsentry_sdk.integrations.opentelemetry.integration.OpenTelemetryIntegrationintegrationsdefault_integrationsauto_enabling_integrations)with_defaultswith_auto_enabling_integrations	spotlightr8   zSetting SDK name to '%s'zCan not set up profiler. (%s)r   )(_client_init_debugrX   setrg   r   rp   rq   r%   r   session_flusherrr   r   r   sentry_sdk.metricsr3   boolr   info
ValueErrorformatrC   r   OTELr   appendr   r   r   r&   r   rb   keysSDK_INFOr!   r#   ra   r   rR   r   r   )	rs   	old_debugr   experimentsmetrics_supportedr3   r   sdk_namer   s	   `        rj   r   z_Client._init_impl/  s   &**51		:
G	.""4<<#89+DLL9DNDL~~<< >?#*4>>#:DL#1?P#QD &*D#,,**>2>K/6 )2O$;t!$D.?%6.2'OO,CTJ//D+ KKT %K!||34<QQ PWW-  ||N+//0JERW 0</@/@^,%,,` !3^,"ll+AB0401!D "DN||,!0!>#D):):)?)?)A$BCH'HVLL3X>$T\\2E"4<<0
 ""9-##DLL$4$45I2$NO LL&&$T\\2$..-8 '(	 9 ! ELL!@!DDE ""9-s0   J M2 M 	M/M*%M2 *M//M2 2N	c                      y)r   Trx   r~   s    rj   r   z_Client.is_active  s     ru   c                 :    | j                   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)rg   rX   r~   s    rj   r   z_Client.should_send_default_pii  s     || 2E::ru   c                      | j                   d   S )z%Returns the configured DSN as string.r=   r   r~   s    rj   r=   z_Client.dsn  s     ||E""ru   c           	      h   |j                  d      &t        j                  t        j                        |d<   |c|j                  d      dk(  }|j                  ||| j                        }|.| j                  r!| j                  j                  d|rdnd       y |}| j                  d   rnd|vrjd	|vrfd
|vrbt               5  dt        | j                  j                  dd      | j                  j                  dt                    dddgi|d
<   d d d        dD ]M  }|j                  |      | j                  |   %t        | j                  |         j                         ||<   O |j                  d      :t        t              }t!        | j"                  j%                               |d<   ||d<   |j                  d      d|d<   t'        || j                  d   | j                  d   | j                  d         }|1| j                  d   }|r | j                  d   s|j)                  |       |@t+        || j                  j                  d      | j                  j                  d            }| j                  d   }	|	z|x|j                  d      dk7  rdd }
t               5   |	||xs i       }
d d d        |
>t-        j.                  d       | j                  r| j                  j                  dd       |
}| j                  d    }|z|x|j                  d      dk(  rdd }
t               5   |||xs i       }
d d d        |
>t-        j.                  d!       | j                  r| j                  j                  dd       |
}|S # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   fxY w)"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@   rI   distsdkr   platformpythonin_app_excludein_app_includerL   rP   r   r   )r   r   before_sendzbefore send dropped eventbefore_send_transactionz%before send transaction dropped event)rX   r   nowr   utcapply_to_eventrg   rp   record_lost_eventr	   r
   r   rT   striprW   r   sortedr   r   r   scrub_eventr   r   r   )rs   eventhintscopeis_transactionevent_rh   sdk_inforP   r  	new_eventr  s               rj   _prepare_eventz_Client._prepare_event  s    99[!)!)hll!;E+"YYv.-?N))%t||DF ~>>NN44)8F}G 5  E LL,-5(E)&,. *<8<8H8H$=t9" 261A1A$68P2"	+ (-'+$i $ C 	<Cyy~%$,,s*;*G c!2399;c
	< 99U#H~H'-d.?.?.D.D.F'GH^$#E%L99Z ( (E*LL)*LL)*LL(	
 !\\*:;Ndll3E&F**51 &*ll&6&67N&O!%!1!12D!EE ll=1#!		&!]2I,. ;'tzr:	; 78>>NN44%W 5  E"&,,/H"I#/!		&!]2I,. G3E4:2F	G CD>>NN44%] 5  Ei r; ;"G Gs%   AN*N5N(NN%(N1c                     |j                  d      }|y|d   }t        |d         }|d   j                  d|}| j                  d   D ]-  }t	        |t
              r||k(  s||k(  s yt        ||      s- y y)Nexc_infoFr   r   ignore_errorsT)rX   r   r   rg   rR   rT   
issubclass)rs   r  r  r  r   error_type_nameerror_full_nameignored_errors           rj   _is_ignored_errorz_Client._is_ignored_error  s    88J''4%-a[%;%;_M!\\/: 	 M -- O3}7We]3	  ru   c                     |j                  d      dk(  }|ry|d uxr |j                   }|ry| j                  ||      }|ryy)Nr   r   TF)rX   _should_capturer  )rs   r  r  r  r  ignoring_prevents_recursionignored_by_config_options          rj   r  z_Client._should_capture1  sX     6*m;&+4&7&U@U@U<U#&#'#9#9%#F #ru   c                 0   | j                   j                  dd       }t        |      rt               5   |||      }d d d        n| j                   d   }	 dk  xr t	        j                         |k\  }|r*| j                  r| j                  j                  dd       yy# 1 sw Y   UxY w# t
        $ r t        j                  d       d}Y [t        $ r? t        |      rdnd\  }}t        j                  d|d	|d
t              d       d}Y w xY w)Nerror_samplersample_raterO   zMThe provided error_sampler raised an error. Defaulting to sampling the event.F)r!  returned)r"  containszThe provided  z an invalid value of zJ. The value should be a float or a bool. Defaulting to sampling the event.r   r   T)rg   rX   callabler	   random	NameErrorr   rc   rV   reprrp   r  )rs   r  r  r!  r"  not_in_sample_rate	parameterverbs           rj   _should_sample_errorz_Client._should_sample_errorG  s    (($?M",. 9+E489 9 ,,}5K	'!,s!2!Uv}}+7U0 ~~00g0VK9 9  	'NN_ "' 	' M* .0 It
 NNdD$57 "'	's$   
B B,  B), DADDc                 <   d}d}d }|j                  d      xs i j                  d      }|rBd}|D ];  }|j                  d      }t        |t              s%|j                  d      du s9d} n |j                  d      }	|j                  g|j                  d      xs i j                  d	      }
t        |
t              r|
ni }|j                         D ]  \  }}|j                         d
k(  s|} n |j                  |rdnd |	||j                  |xs |z          y )NFr   r   T	mechanismhandleduserrequestheadersz
user-agentr   )statusr1  
user_agenterrors)	rX   rR   r   r5  rW   rY   r\   updater6  )rs   sessionr  r   erroredr5  
exceptionsr   r/  r1  r3  headers_dictkvs                 rj   _update_session_from_eventz"_Client._update_session_from_eventw  s&    
ii,277A
G# !IIk2	i1immI6NRW6W"G	 yy %yy+1r66yAG&0$&?7RL$**, 1779,!"J
 	 '9T!>>W%78	 	 	
ru   c                    t        j                  d      ry|i }|j                  d      }t        |xs d      }|#t        j                         j
                  x|d<   }| j                  |||      sy|j                  dd      }| j                  |||      }|y|r|j                  nd}|r| j                  ||       |j                  d      dk(  }|j                  d      dk(  }	|s|	s| j                  ||      sy|j                  d	      }
|j                  d
i       j                  d      xs i }|j                  di       }|d   t        t        j                  t        j                               d}|r||d<   t#        |      }|rMt%        |t&              r+|j)                  |j+                  || j,                               |j/                  |       n%|	r|j1                  |       n|j3                  |       |
xs dD ]!  }|j5                  |j7                                # | j8                  r| j8                  j;                  |       | j<                  y| j<                  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_idrx   profiler   r   check_inattachmentscontextsr   dynamic_sampling_context)r@  sent_at)r3  )r   rX   rW   uuiduuid4hexr  popr  _sessionr>  r-  r   r   r  r   r  r    rR   r"   add_profileto_jsonrg   add_transactionadd_checkin	add_eventadd_itemto_envelope_itemr   r   rp   )rs   r  r  r  r@  rA  	event_optr8  r  
is_checkinrC  trace_contextrE  r3  r   
attachments                   rj   r   z_Client.capture_event  sD   " !$$U+<D99Z(DJB+/::<+;+;;E*##E47))It,''tU;	 %*%..t++GU;"v.-?]]6*j8
 --eT:hh}-!j"599'BHb#0#4#45OQS#T  "*-'X\\(BC

 $7GGG,'7+$$W__Y%MN$$Y/  +y)%+ 	=Jj99;<	= >>NN++H5>>!''1ru   c                 ~    |j                   st        j                  d       y | j                  j	                  |       y )Nz3Discarded session update because of missing release)r?   r   r   r   add_session)rs   r8  s     rj   r   z_Client.capture_session  s,     KKMN  ,,W5ru   c                     t        |t              r|}n$|j                  |j                  }nt        d      | j                  j                  |      S )zReturns the integration for this client by name or class.
        If the client does not have that integration then `None` is returned.
        zIntegration has no name)rR   rT   
identifierr   r   rX   )rs   name_or_classintegration_names      rj   r   z_Client.get_integration  sP     mS),%%1,77677  $$%566ru   c                 R   | j                   | j                  ||       | j                  j                          | j                  | j                  j                          | j
                  r| j
                  j                          | j                   j                          d| _         yy)z
        Close the client and shut down the transport. Arguments have the same
        semantics as :py:meth:`Client.flush`.
        Ntimeoutcallback)rp   r   r   killrr   rq   rs   r_  r`  s      rj   r   z_Client.close  s     >>%JJwJ:  %%'&&2'',,.||!!#NN!!DN &ru   c                     | j                   o|| j                  d   }| j                  j                          | j                  | j                  j                          | j                   j                  ||       yy)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^  )rp   rg   r   r   rr   rb  s      rj   r   z_Client.flush"  sn     >>%,,'9:  &&(&&2''--/NN  8 D &ru   c                     | S ro   rx   r~   s    rj   r   z_Client.__enter__7  r   ru   c                 $    | j                          y ro   )r   r   s       rj   r   z_Client.__exit__;  s    

ru   ro   )NN)r   r   r   r   rt   rz   r|   r   r   r   r   r   r=   r  r  r  r-  r>  r   r   r   r   r   r   r   __classcell__)r   s   @rj   r   r      s    
)
2h\)|; # #
tl4 	,.`#
P 	Wr67$ ", E*ru   r   c                       e Zd Zy)r   Nr   r   r   rx   ru   rj   r   r   I      ru   r   c                       e Zd Zy)ClientNri  rx   ru   rj   rl  rl  L  rj  ru   rl  c                      t         S ro   )rk   rx   ru   rj   <lambda>rn  U  s    < ru   c                      t         S ro   )r   rx   ru   rj   rn  rn  V  s    g ru   )XrZ   rG  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/   r0   r1   r   r3   sentry_sdk.scoper4   sentry_sdk.sessionr5   r6   r   r   rk   ModuleNotFoundErrorr   ra   ImportErrorrm   r   r   rT   r   rl  rx   ru   rj   <module>r     sF   	    # ' # ?   , $ >  N ' . ( N N - & 0 +-34&*.   34  +@A@F)0E EP	 	Z	j Z	z ,'c3h "G  (*K FU  )()s   E$ $E.-E.