U \f@sddlZddlmZmZddlmZddlmZmZm Z m Z ddl m Z ddl mZddZd d ZGd d d e Zd dZddZdS)N)Hub_should_send_default_pii)reraise)AnnotatedValuecapture_internal_exceptionsevent_from_exceptionlogger) Integration)_filter_headerscsfdd}|S)Nc stj}|t}|dkr*||f||S|}t&||j|_| t ||W5QRXz ||f||WW5QRSt k rt }t||jjdddd\}}|j||dt|YnXW5QRXdS)N aws_lambdaF)typeZhandled)Zclient_optionsZ mechanism)hint)rcurrentget_integrationAwsLambdaIntegrationZ push_scoperZclear_breadcrumbs function_nameZ transactionZadd_event_processor_make_request_event_processor Exceptionsysexc_inforclientZoptionsZ capture_eventr) eventcontextargskwargshub integrationZscoperr handler/aws_lambda.pysentry_handlers(    z%_wrap_handler..sentry_handlerr)rr!rrr _wrap_handlers r"c Cs8t(tj}|t}|dk r*|jW5QRXdSN)rrrrrrflush)rrrrr _drain_queue+s  r%c@seZdZdZeddZdS)rr csddl}d}t|ds.sentry_handle_event_requestcst|}|f||Sr#r(r))old_handle_http_requestrr sentry_handle_http_requestXszCAwsLambdaIntegration.setup_once..sentry_handle_http_requestcst||Sr#r%rr) old_to_jsonrr sentry_to_jsoncsz7AwsLambdaIntegration.setup_once..sentry_to_jsoncst|}||f||Sr#r()Zlambda_runtime_clientr*rrr+rr r-kscsfdd}|S)Ncst||Sr#r0r1frr inneryszKAwsLambdaIntegration.setup_once.._wrap_post_function..innerr)r5r6rr4r _wrap_post_functionxs z._wrap_post_function) __main__hasattrZ bootstrap ImportErrorrZwarningr'r&Zto_jsonZLambdaRuntimeClientZpost_invocation_resultZpost_invocation_error)Zlambda_bootstrapZpre_37r-r/r3r7r)r,r.r2r setup_once8sB      zAwsLambdaIntegration.setup_onceN)__name__ __module__ __qualname__Z identifier staticmethodr;rrrr r5srcsfdd}|S)Ncs |di}jjjjd|d<|di}dkrLd|d<t|d<dkrnd|d <d krtd |d <d drt d d ddddggi|d<t r|di}did}|dk r||d<did}|dk r||d<|S)Nextra)Zremaining_time_in_millisrfunction_versioninvoked_function_arnaws_request_idlambdarequestZ httpMethodmethodZurlZqueryStringParametersZ query_stringheadersZbodyZremz!rawxrdatauserZidentityZuserArnidZsourceIpZ ip_address) setdefaultZget_remaining_time_in_millisrrArBrC_get_urlr getrr)rr r@rEZ user_inforLZip aws_context aws_eventrr event_processors4        z6_make_request_event_processor..event_processorr)rRrQrSrrPr rs)rcCsV|dd}|di}|dd}|dd}|rJ|rJ|rJd|||Sd|jS)NpathrGZHostzX-Forwarded-Protoz {}://{}{}zawslambda:///{})rOformatr)rrrTrGZhostprotorrr rNs     rN)rZsentry_sdk.hubrrZsentry_sdk._compatrZsentry_sdk.utilsrrrrZsentry_sdk.integrationsr Z$sentry_sdk.integrations._wsgi_commonr r"r%rrrNrrrr s    R-