U 췀gR@sddlZddlZddlZddlZddlmZddlmZmZddlm Z ddl m Z m Z ddl mZmZddlmZmZmZmZmZmZmZmZmZmZmZddlmZdd lmZdd l m!Z!m"Z"dd l#m$Z$m%Z%m&Z&m'Z'm(Z(dd l)m*Z*m+Z+dd l,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3m4Z4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;ddl mZ>ddl m?Z?ddl m@Z@ddl mAZAddl mBZBddl mCZCddl mDZDddlEmFZFmGZGmHZHddl)mIZIddlJmKZKdd lLmMZMdd!lNmOZOdd"l:mPZPdd#l mQZQeDd$eId%ZRed&ZSd'e'd(e'd)gd*ZTd+d,ZUzeVZWWneXk rleYZWYnXGd-d.d.ZZGd/d0d0eZZ[Gd1d2d2eZZ\ddl mr?packagescOs.|r8t|dttfs"|ddkr8|d}|dd}nd}t|dkrPtdtt}t||}|dk r|ddkr||d<|D]&\}}||krtd|f|||<q|ddkrt j d|d<|ddkrt |d<|ddkrt j d pd |d<|d dkr,t t j d d dd|d <|ddkrRt tdrRt|d<|ddkrjtj|d<|ddkrz t }Wntk rd}YnX||d<|ddkr|ddkrd|d<|ddkrt|ddkrdn|dd|d<|dr*t|dts*tdd|d<|S)Nrz+Only single positional argument is expecteddsnzUnknown option %rZ SENTRY_DSNrelease environmentZSENTRY_ENVIRONMENT productiondebugZ SENTRY_DEBUGFalseTstrict server_name gethostname instrumenter project_rootZenable_tracingZtraces_sample_rate?event_scrubbersend_default_piiF)rPsocket_optionszxIgnoring socket_options because of unexpected format. See urllib3.HTTPConnection.socket_options for the expected format.) isinstancebytesstrlen TypeErrordictrgetitemsosenvironrr hasattrsocketrKrZSENTRYgetcwd Exceptionr&listrwarning)argskwargsrBrvoptionskeyvaluerMrh?/opt/hc_python/lib/python3.8/site-packages/sentry_sdk/client.py _get_optionsOsX"           rjc@seZdZdZdZdddZddZddZed d Z d d Z d dZ ddZ ddZ erreddZeddZddZddZddZddZddZdS) BaseClientzp .. versionadded:: 2.0.0 The basic definition of a client that is used for sending data to Sentry. NcCs(|dk r |nt|_d|_d|_d|_dSN)rre transportmonitormetrics_aggregator)selfrerhrhri__init__s zBaseClient.__init__cOsdiiSNrerhrprbrcrhrhri __getstate__szBaseClient.__getstate__cOsdSrlrhrsrhrhri __setstate__szBaseClient.__setstate__cCsdSrlrhrprhrhrirBszBaseClient.dsncCsdS)NFrhrvrhrhrishould_send_default_piisz"BaseClient.should_send_default_piicCsdS)u .. versionadded:: 2.0.0 Returns whether the client is active (able to send data to Sentry) Frhrvrhrhri is_activeszBaseClient.is_activecOsdSrlrhrsrhrhri capture_eventszBaseClient.capture_eventcOsdSrlrhrsrhrhricapture_sessionszBaseClient.capture_sessioncCsdSrlrhrp name_or_classrhrhriget_integrationszBaseClient.get_integrationcCsdSrlrhr|rhrhrir~scCsdSrlrhr|rhrhrir~scOsdSrlrhrsrhrhricloseszBaseClient.closecOsdSrlrhrsrhrhriflushszBaseClient.flushcCs|Srlrhrvrhrhri __enter__szBaseClient.__enter__cCsdSrlrhrpexc_type exc_valuetbrhrhri__exit__szBaseClient.__exit__)N)__name__ __module__ __qualname____doc__ spotlightrqrtrupropertyrBrwryrzr{r)rr~rrrrrhrhrhrirks*     rkc@seZdZdZdS)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)rrrrrhrhrhrirsrcseZdZdZfddZddZddZdd Zd d Zd d Z ddZ e ddZ ddZ ddZd-ddZddZddZd.ddZdd Zered!d"Zed#d"Zd$d"Zd/d%d&Zd0d'd(Zd)d*Zd+d,ZZS)1_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) cs$tt|jt||d|dS)Nre)superrrq get_options _init_implrs __class__rhrirqsz_Client.__init__cCs d|jiSrrrrvrhrhrirt sz_Client.__getstate__cCs|d|_|dSrr)rer)rpstaterhrhriru s z_Client.__setstate__c CsX|D]L}d}|d}|dd\}}z2t|}t||}t||t|td|Wqtk r z~|dd\}}t|}t||} t| |}t| j |} t|} | t t fkrt | } t| || t||| td|Wn2t k r} zt d|| W5d} ~ XYnXYqt k rP} zt d|| W5d} ~ XYqXqdS)z Instruments the functions given in the list `functions_to_trace` with the `@sentry_sdk.tracing.trace` decorator. NZqualified_name.rAzEnabled tracing for %szWCan not enable tracing for '%s'. (%s) Please check your `functions_to_trace` parameter.)rsplitrgetattrsetattrrrrFmodule_not_found_errortype__dict__ staticmethod classmethodr_ra) rpfunctions_to_tracefunction class_nameZfunction_qualname module_nameZ function_nameZ module_objZ function_objZ class_objZ function_typeZtraced_functionerhrhri_setup_instrumentationsD       z_Client._setup_instrumentationc std}fdd}z\tjdtj_d_jrXjdrXtj_t|d_ d_ jdi}|dd rt pt }|rd d l m}||t|d d d _ n tdd}jd|krtd|jdddr$tdtjjd<dtkr$tdtjdjdjdjdd_jd}|dkrdtjkrtjd}t|d d}|dk r|n|jd<jdrtj_t t!j"} | t#d<td| t$jr,zt%jWn0t&k r(} ztd | W5d} ~ XYnXnFzt'jt#|d!Wn0t&k rp} ztd"| W5d} ~ XYnXW5t|X(jd#gjsj st$jst)jt*rt+dS)$NFcsjdk rj|dSrl)rmcapture_envelope)envelopervrhri_capture_envelopeIs z-_Client._init_impl.._capture_enveloperFZenable_backpressure_handling) capture_funcZ _experimentsZenable_metricsTrr6Zmetric_code_locations)rZenable_code_locationsz:Metrics not supported on Python 3.6 and lower with gevent.)alwaysneverZsmallZmediummax_request_body_sizez:Invalid value for max_request_body_size. Must be one of {}Zotel_powered_performancezA[OTel] Enabling experimental OTel-powered performance monitoring.rLzJsentry_sdk.integrations.opentelemetry.integration.OpenTelemetryIntegration integrationsZdefault_integrationsZauto_enabling_integrationsdisabled_integrations)Z with_defaultsZwith_auto_enabling_integrationsrrZSENTRY_SPOTLIGHTrHr>zSetting SDK name to '%s'zCan not set up profiler. (%s))sdk_inforz(Can not set up continuous profiler. (%s)r),_client_init_debugrXsetrerrmrnr'r session_flusherrorrsentry_sdk.metricsr7boolrinfo ValueErrorformatrFrZOTELrappendrrrZr[r r(rrr`keysSDK_INFOr#r%r_r"rrRrr ) rpZ old_debugrZ experimentsZmetrics_supportedr7rZspotlight_configZspotlight_env_valueZsdk_namerrhrvrirEs                    "  z_Client._init_implcCsdS)rxTrhrvrhrhrirysz_Client.is_activecCs.|jd}|dkr*|jd o(|jdk }|S)z .. versionadded:: 2.0.0 Returns whether the client should send default PII (Personally Identifiable Information) data to Sentry. rPNrB)rerXr)rpresultrhrhrirws z_Client.should_send_default_piicCs |jdS)z%Returns the configured DSN as string.rBrrvrhrhrirBsz _Client.dsnc Cs|ddkrttj|d<|dk r|ddk}t|dg}||||j}|dkr|jr|jj d|rrdndd|r|jj dd|d d dS|}|t|dg}|r|d kr|jdk r|jj dd|d |jd rFd |krFd|krFd|krFt 8dt |jdd|jdt ddddgi|d<W5QRXdD]<}||dkrJ|j|dk rJt |j|||<qJ|ddkrtt} t|j| d<| |d<|ddkrd|d<t||jd|jd|jd}|dk r|jd} | r| ||dk rTtd ttd!||jd"|jd|jd#d$}|jd%} | dk r|dk r|ddkrd} t | ||pi} W5QRX| dkrtd&|jr|jj d%dd| }|jd'} | dk r|dk r|ddkrd} t|dg}t | ||p.i} W5QRX| dkrtd(|jr|jj d%dd)|jj d%d|d d*n<|t| dg}|d kr|jdk r|jj d%d|d*| }|S)+N timestampr transactionspansZevent_processorerror data_categoryspanrA)rquantityrZattach_stacktrace exception stacktracethreadsvaluesinclude_local_variablesTmax_value_length)rrF)rcrashedcurrent)rCrDrJdistZsdkrplatformpythonZin_app_excludeZin_app_includerMrOr2zDict[str, Any]r custom_repr)rrr before_sendzbefore send dropped eventbefore_send_transactionz%before send transaction dropped event)reasonr)rrr)rXrnowrutcrUZapply_to_eventrermrecord_lost_eventr r rrTstriprWrsortedrrrZ scrub_eventrrrr)rpeventhintscopeis_transactionZ spans_beforeZevent_Z spans_deltarfrrOrZ new_eventrrhrhri_prepare_events                 z_Client._prepare_eventcCs|d}|dkrdS|d}t|d}d|dj|f}|jdD]6}t|trl||ksd||kr|dSqFt||rFdSqFdS)Nexc_infoFrz%s.%s ignore_errorsT)rXrrrerRrT issubclass)rprrrrZerror_type_nameZerror_full_nameZ ignored_errorrhrhri_is_ignored_errorjs    z_Client._is_ignored_errorNcCsF|ddk}|rdS|dk o$|j }|r.dS|||}|rBdSdS)NrrTF)rX_should_capturer)rprrrrZignoring_prevents_recursionZignored_by_config_optionrhrhrirs z_Client._should_capturec Cs|jdd}t|r4t|||}W5QRXn |jd}z|dkoRt|k}Wndtk rxtdd}YnDtk rt|rdnd\}}td||t |fd}YnX|r|j r|j j dd d dSd S) N error_sampler sample_raterNzMThe provided error_sampler raised an error. Defaulting to sampling the event.F)rZreturned)rcontainszsThe provided %s %s an invalid value of %s. The value should be a float or a bool. Defaulting to sampling the event.rrT) rerXcallabler random NameErrorrrarVreprrmr)rprrrrZnot_in_sample_rateZ parameterZverbrhrhri_should_sample_errors8   z_Client._should_sample_errorcCsd}d}d}|dpid}|r\d}|D].}|d}t|tr,|ddkr,d}q\q,|d} |jdkr|dp|id } t| tr| ni} | D]\} } | d kr| }qq|j|rd nd| ||j|p|d dS) NFrrT mechanismZhandleduserrequestheadersz user-agentr)statusr user_agenterrors) rXrRrrrWrYlowerupdater)rpsessionrrZerroredr exceptionsrrrrZ headers_dictkvrhrhri_update_session_from_events2      z"_Client._update_session_from_eventcCst|pd}||||sdS|dd}|d}|dkrNtj|d<}||||}|dkrhdS|rr|jnd}|r| |||ddk}|ddk} |s| s| ||sdS|d} |d id pi} | d i} |dt t tjd } | r| | d <t| d }|rJt|tr>||||j||n| r\||n ||| pndD]}||qpd}|jr|j||}|jdk r|j||}|S)aCaptures 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. rhNprofileevent_idrrZcheck_in attachmentsZcontextsrdynamic_sampling_context)rZsent_at)r)rWrpoprXuuiduuid4hexr_sessionrrrrrrrr!rRr$Z add_profileto_jsonreZadd_transactionZ add_checkinZ add_eventZadd_itemZto_envelope_itemrrrm)rprrrrrZ event_optrrZ is_checkinrZ trace_contextrrr attachmentZ return_valuerhrhrirzs`               z_Client.capture_eventcCs"|jstdn |j|dS)Nz3Discarded session update because of missing release)rCrrrZ add_session)rprrhrhrir{@s z_Client.capture_sessioncCsdSrlrhr|rhrhrir~Ksz_Client.get_integrationcCsdSrlrhr|rhrhrir~PscCs6t|tr|}n|jdk r"|j}ntd|j|S)zReturns the integration for this client by name or class. If the client does not have that integration then `None` is returned. NzIntegration has no name)rRrT identifierrrrX)rpr}Zintegration_namerhrhrir~Us   cCsZ|jdk rV|j||d|j|jdk r6|j|jrF|j|jd|_dS)z Close the client and shut down the transport. Arguments have the same semantics as :py:meth:`Client.flush`. Ntimeoutcallback)rmrrkillrornrprrrhrhrires      z _Client.closecCsN|jdk rJ|dkr|jd}|j|jdk r:|j|jj||ddS)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. NZshutdown_timeoutr)rmrerrrorrhrhrirys     z _Client.flushcCs|Srlrhrvrhrhrirsz_Client.__enter__cCs |dSrl)rrrhrhrirsz_Client.__exit__)N)NN)NN)NN)rrrrrqrtrurrryrwrrBrrrrrrzr{r)rr~rrrr __classcell__rhrhrrirsF 3u    0( U     rc@s eZdZdS)rNrrrrhrhrhrirsrc@s eZdZdS)ClientNr rhrhrhrir sr cCstSrl)rjrhrhrhrir cCstSrl)rrhrhrhrir r )`rZrrr]collections.abcrrr importlibrtypingrrZsentry_sdk._compatrr Zsentry_sdk.utilsr r r r rrrrrrrZsentry_sdk.serializerrZsentry_sdk.tracingrZsentry_sdk.transportrrZsentry_sdk.constsrrrrrZsentry_sdk.integrationsrrZsentry_sdk.sessionsr Zsentry_sdk.enveloper!Z'sentry_sdk.profiler.continuous_profilerr"Z(sentry_sdk.profiler.transaction_profilerr#r$r%Zsentry_sdk.scrubberr&Zsentry_sdk.monitorr'Zsentry_sdk.spotlightr(r)r*r+r,r-r.r/r0r1Zsentry_sdk._typesr2r3r4r5rr7Zsentry_sdk.scoper8Zsentry_sdk.sessionr9r:r;r<rrrjModuleNotFoundErrorrr_ ImportErrorrkrrrTrr rhrhrhris~  4                         C V "