Looking for instructions on how to add Sentry without modifying your code? Check out these docs instead.
Create a deployment package on your local machine and install the required dependencies in the deployment package. For more information, see AWS Lambda deployment package in Python.
Install our Python SDK using
pip install --upgrade sentry-sdk
We also support installing Sentry as a Container Image and installing Sentry in Lambda Layer.
You can use the AWS Lambda integration for the Python SDK like this:
import sentry_sdk from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration sentry_sdk.init( dsn="https://examplePublicKey@o0.ingest.sentry.io/0", integrations=[ AwsLambdaIntegration(), ], # Set traces_sample_rate to 1.0 to capture 100% # of transactions for performance monitoring. # We recommend adjusting this value in production, traces_sample_rate=1.0, ) def my_function(event, context): # ...
Check out Sentry's AWS sample apps for detailed examples.
If you are using another web framework inside of AWS Lambda, the framework might catch those exceptions before we get to see them. Make sure to enable the framework specific integration as well, if one exists. See the Python main page for more information.
The timeout warning reports an issue when the function execution time is near the configured timeout.
To enable the warning, update the SDK initialization to set
sentry_sdk.init( dsn="https://examplePublicKey@o0.ingest.sentry.io/0", integrations=[ AwsLambdaIntegration(timeout_warning=True), ], # Set traces_sample_rate to 1.0 to capture 100% # of transactions for performance monitoring. # We recommend adjusting this value in production, traces_sample_rate=1.0, )
The timeout warning is sent only if the timeout in the Lambda Function configuration is set to a value greater than one second.
With the AWS Lambda integration enabled, the Python SDK will:
Automatically report all events from your Lambda Functions.
You can modify the transaction sample rate using
Event reports automatically include:
- A link to CloudWatch Logs
- Function details
sys.argvfor the function
- AWS Request ID
- Function execution time
- Function version
- You can add more data as described here
Request data is attached to all events: HTTP method, URL, headers, form data, JSON payloads. Sentry excludes raw bodies and multipart file uploads. Sentry also excludes personally identifiable information (such as user ids, usernames, cookies, authorization headers, IP addresses) unless you set
Each request has a separate scope. Changes to the scope within a view, for example setting a tag, will only apply to events sent as part of the request being handled.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").