U \!@sddlZddlZddlZddlmZddlmZmZddlmZm Z m Z m Z m Z m Z mZmZddlmZddlmZmZddlmZddlmZed Zd d ZGd d d eZ dS)N)datetime) string_types text_type)strip_event_mutflatten_metadata convert_types handle_in_app get_type_namecapture_internal_exceptionscurrent_stacktracelogger)make_transport)DEFAULT_OPTIONSSDK_INFO)setup_integrations) ContextVarZclient_init_debugcOs|r4t|dts|ddkr4|d}|dd}nd}tt}t||}|dk rh|ddkrh||d<|D]&\}}||krtd|f|||<qp|ddkrtjd|d<|ddkrtjd|d<|ddkrtjd |d<|S) NrdsnzUnknown option %rZ SENTRY_DSNreleaseZSENTRY_RELEASE environmentZSENTRY_ENVIRONMENT) isinstancerdictrgetitems TypeErrorosenviron)argskwargsrrvoptionskeyvaluer# /client.py get_options!s&     r%c@sleZdZdZddZeddZddZdd Zdd d Z dd dZ dddZ dddZ ddZ ddZd 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 Os|td}z`t|||_}t|dt||_d}|d|krRtd|t |d|dd|_ W5t|XdS) NFdebug)alwaysneverZsmallZmediumrequest_bodiesz3Invalid value for request_bodies. Must be one of {} integrationsZdefault_integrations)Z with_defaults) _client_init_debugrsetr%r r transport ValueErrorformatrr+)selfrrZ old_debugr r*r#r#r$__init__Fs"    zClient.__init__cCs |jdS)z%Returns the configured DSN as string.r)r r1r#r#r$r\sz Client.dsnc Cs|ddkrt|d<|dk r:|||}|dkr:dS|jdrd|krd|krd|krt"t|jdddd g|d<W5QRXd D]6}||dkr|j|dk rt|j|||<q|d dkrt t }t |j |d <||d <|d dkrd|d <t||jd|jd}|dk rHt|}t|t|}|jd}|dk rd}t|||}W5QRX|dkrtd||}|S)NZ timestampZattach_stacktraceZ exception stacktraceZthreadsZ with_localsFT)r4ZcrashedZcurrent)rrZ server_nameZdistZsdkr+platformpythonZin_app_excludeZin_app_include before_sendzbefore send dropped event (%s))rrZutcnowZapply_to_eventr r r rstriprrsortedr+keysrrrrr info)r1eventhintscoper!Zsdk_infor7Z new_eventr#r#r$_prepare_eventas^        zClient._prepare_eventcCs~|d}|dkrdSt|d}d|dj|f}|jdD]:}t|trd||ks\||krxdSq>t|d|r>dSq>dS)Nexc_infoFrz%s.%s ignore_errorsT)rr __module__r rr issubclass)r1r<r=r@Z type_nameZ full_nameZerrclsr#r#r$_is_ignored_errors   zClient._is_ignored_errorNcCsJ|dk r|jsdS|jddkr6t|jdkr6dS|||rFdSdS)NFZ sample_rateg?T)_should_capturer randomrD)r1r<r=r>r#r#r$rEs  zClient._should_capturecCsz|jdkrdS|dkri}|d}|dkr>tj|d<}||||sPdS||||}|dkrjdS|j||S)aCaptures an event. This takes the ready made event and an optoinal hint and scope. The hint is internally used to further customize the representation of the error. When provided it's a dictionary of optional information such as exception info. If the transport is not set nothing happens, otherwise the return value of this function will be the ID of the captured event. NZevent_id)r.ruuidZuuid4hexrEr? capture_event)r1r<r=r>rr#r#r$rIs   zClient.capture_eventcCs,|jdk r(|j||d|jd|_dS)z| Close the client and shut down the transport. Arguments have the same semantics as `self.flush()`. Ntimeoutcallback)r.flushkillr1rKrLr#r#r$closes  z Client.closecCs0|jdk r,|dkr|jd}|jj||ddS)a{ Wait `timeout` seconds for the current events to be sent. If no `timeout` is provided, the `shutdown_timeout` option value is used. The `callback` is invoked with two arguments: the number of pending events and the configured timeout. For instance the default atexit integration will use this to render out a message on stderr. NZshutdown_timeoutrJ)r.r rMrOr#r#r$rMs  z Client.flushcCs|SNr#r3r#r#r$ __enter__szClient.__enter__cCs |dSrQ)rP)r1exc_type exc_valuetbr#r#r$__exit__szClient.__exit__)N)NN)NN)NN)__name__rB __qualname____doc__r2propertyrr?rDrErIrPrMrRrVr#r#r#r$r&?s ?   r&)!rrGrFrZsentry_sdk._compatrrZsentry_sdk.utilsrrrrr r r r Zsentry_sdk.transportr Zsentry_sdk.constsrrZsentry_sdk.integrationsrrZ ClientOptionsZScopeZAnyZDictZOptionalr,r%objectr&r#r#r#r$s (