B Y@srdZddlmZddlZddlZddlZddlmZddlm Z ddl m Z e dZ dd ZGd d d e ZdS) z raven.contrib.awslambda ~~~~~~~~~~~~~~~~~~~~ Raven wrapper for AWS Lambda handlers. :copyright: (c) 2010-2012 by the Sentry Team, see AUTHORS for more details. :license: BSD, see LICENSE for more details. )absolute_importN) FunctionType)Client) HTTPTransportzsentry.errors.clientcCsdddddddS)NZAWS_LAMBDA_FUNCTION_NAMEZAWS_LAMBDA_FUNCTION_VERSIONZAWS_LAMBDA_FUNCTION_MEMORY_SIZEZAWS_LAMBDA_LOG_GROUP_NAMEZAWS_LAMBDA_LOG_STREAM_NAMEZ AWS_REGION)lambdaversionZ memory_sizeZ log_groupZ log_streamZregionrrrQ/opt/alt/python37/lib/python3.7/site-packages/raven/contrib/awslambda/__init__.pyget_default_tagss r csfeZdZdZfddZfddZfddZdd d Zed d Z ed dZ eddZ Z S) LambdaClienta Raven decorator for AWS Lambda. By default, the lambda integration will capture unhandled exceptions and instrument logging. Usage: >>> from raven.contrib.awslambda import LambdaClient >>> >>> >>> client = LambdaClient() >>> >>> @client.capture_exceptions >>> def handler(event, context): >>> ... >>> raise Exception('I will be sent to sentry!') cs*|dt}tt|j|d|i|dS)N transport)getrsuperr __init__)selfargskwargsr ) __class__rr r8s zLambdaClient.__init__csd|kri|d<}n|d}|dd}|dd}||}|rN|||rz||}|rj||||||d<tt|j||S)Ndataeventcontextextra)r _get_user_interfaceupdate_get_http_interface_get_extra_datarr capture)rrrrrrZ user_infoZ http_info)rrr r<s      zLambdaClient.capturecsntt|j||}x.tD] \}}|d|tj|qW|dtjd|dtjd|S)NZtagsreleaseZSENTRY_RELEASE environmentZSENTRY_ENVIRONMENT) rr build_msgr items setdefaultosenvironr )rrrroptiondefault)rrr rMs zLambdaClient.build_msgNcsBttstjjdSp"tftfdd}|S)a Wrap a function or code block in try/except and automatically call ``.captureException`` if it raises an exception, then the exception is reraised. By default, it will capture ``Exception`` >>> @client.capture_exceptions >>> def foo(): >>> raise Exception() >>> with client.capture_exceptions(): >>> raise Exception() You can also specify exceptions to be caught specifically >>> @client.capture_exceptions((IOError, LookupError)) >>> def bar(): >>> ... ``kwargs`` are passed through to ``.captureException``. ) exceptionscsNy||f||Sk rHjf||d|jYnXdS)N)rr)ZcaptureExceptionrclear)rrrr)r&frrr wrappedts  z0LambdaClient.capture_exceptions..wrapped) isinstancer functoolspartialcapture_exceptions Exceptionwraps)rr(r&r)r)r&r(rr r-Vs   zLambdaClient.capture_exceptionscCsr|drn|dd}|rn|ddp0|dd|dd|dd|dd|dd|dd }d|iSdS) NZrequestContextidentityZcognitoIdentityIduserZsourceIpZcognitoIdentityPoolIdZcognitoAuthenticationTypeZ userAgent)idusernameZ ip_addressZcognito_identity_pool_idZcognito_authentication_typeZ user_agent)r )rr0r1rrr r~s      z LambdaClient._get_user_interfacecCsN|drJ|drJ|d|d|dd|ddp s