AWS Lambda using serverless doesn't report to sentry
See original GitHub issueThe following code doesn’t report to sentry, but I expected the message to show up -
import os
import sentry_sdk
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
# my script
import cleanup
def run(event, context):
with sentry_sdk.init(dsn=os.getenv("SENTRY_DSN"), debug=True, integrations=[AwsLambdaIntegration()]):
sentry_sdk.capture_message("foo")
cleanup.run()
These are my logs -
START RequestId: f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 Version: $LATEST
[sentry] DEBUG: Setting up integrations (with default = True)
2019-03-17 11:35:25.444 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Setting up integrations (with default = True)
2019-03-17 11:35:25.444 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Enabling integration aws_lambda
2019-03-17 11:35:25.444 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Enabling integration logging
2019-03-17 11:35:25.444 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Enabling integration stdlib
2019-03-17 11:35:25.445 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Enabling integration excepthook
2019-03-17 11:35:25.445 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Enabling integration dedupe
2019-03-17 11:35:25.445 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Enabling integration atexit
2019-03-17 11:35:25.445 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Enabling integration modules
2019-03-17 11:35:25.445 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Enabling integration argv
2019-03-17 11:35:25.445 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Enabling integration threading
[sentry] DEBUG: Enabling integration aws_lambda
[sentry] DEBUG: Enabling integration logging
[sentry] DEBUG: Enabling integration stdlib
[sentry] DEBUG: Enabling integration excepthook
[sentry] DEBUG: Enabling integration dedupe
[sentry] DEBUG: Enabling integration atexit
[sentry] DEBUG: Enabling integration modules
[sentry] DEBUG: Enabling integration argv
[sentry] DEBUG: Enabling integration threading
[sentry] DEBUG: Flushing HTTP transport
[sentry] DEBUG: background worker got flush request
2019-03-17 11:35:25.454 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Flushing HTTP transport
2019-03-17 11:35:25.454 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] background worker got flush request
[sentry] DEBUG: Sending info event [01098f8116294a5f8dffa2ff8b9fdf3e] to sentry.io project:1301031
2019-03-17 11:35:25.454 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Sending info event [01098f8116294a5f8dffa2ff8b9fdf3e] to sentry.io project:1301031
2019-03-17 11:35:25.454 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Starting new HTTPS connection (1): sentry.io:443
[sentry] DEBUG: 0 event(s) pending on flush
2019-03-17 11:35:25.554 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] 0 event(s) pending on flush
[sentry] DEBUG: background worker flushed
2019-03-17 11:35:27.454 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] background worker flushed
[sentry] DEBUG: Killing HTTP transport
2019-03-17 11:35:27.455 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] Killing HTTP transport
[sentry] DEBUG: background worker got kill request
2019-03-17 11:35:27.455 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [DEBUG] background worker got kill request
[sentry] WARNING: init() called inside of pushed scope. This might be entirely legitimate but usually occurs when initializing the SDK inside a request handler or task/job function. Try to initialize the SDK as early as possible instead.
2019-03-17 11:35:27.455 (+01:00) f4d62f9e-2c8a-4b2c-8357-c3ac39871c29 [WARNING] init() called inside of pushed scope. This might be entirely legitimate but usually occurs when initializing the SDK inside a request handler or task/job function. Try to initialize the SDK as early as possible instead.
local variable 'logger' referenced before assignment: UnboundLocalError
Traceback (most recent call last):
File "/var/task/sentry_sdk/integrations/aws_lambda.py", line 37, in sentry_handler
reraise(*exc_info)
File "/var/task/sentry_sdk/_compat.py", line 52, in reraise
raise value
File "/var/task/sentry_sdk/integrations/aws_lambda.py", line 28, in sentry_handler
return handler(event, context, *args, **kwargs)
File "/var/task/handler.py", line 16, in run
cleanup.run()
File "/var/task/cleanup.py", line 43, in run
logger.info("Starting cleanup for registrations older than: %s", before_date)
UnboundLocalError: local variable 'logger' referenced before assignment
END RequestId: f4d62f9e-2c8a-4b2c-8357-c3ac39871c29
I am using sentry-sdk==0.7.6
with https://github.com/UnitedIncome/serverless-python-requirements
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
AWS Lambda | Sentry Documentation
Connect Sentry to your AWS account to automatically add Sentry error and performance monitoring to your Node/Python Lambda functions.
Read more >Serverless Sentry - Serverless Framework: Plugins
This Serverless plugin simplifies integration of Sentry with the popular Serverless Framework and AWS Lambda. Currently we support Lambda Runtimes for ...
Read more >Sentry on AWS lambda in nodejs doesn't send exception
I'm the feeling that is a issue of timing: the lambda is terminated before the data are sent to sentry. Which is the...
Read more >AWS Lambda | Sentry Developer Documentation
Lambda functions can be written in numerous programming languages (Javascript, Python, Ruby, Java, Go, ...). Sentry is currently supporting automatic ...
Read more >Handling Error Conditions Using a Step Functions State ...
Step 1: Create a Lambda Function That Fails · Open the AWS Lambda console at https://console.aws.amazon.com/lambda/ . · Choose Use a blueprint, enter...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes,
capture_message
is not reported as having failed in the logs, when the lambda was not able to connect to internet.However, this works after I fixed my network issue. Thanks for the help 😃
Ah, so you’re saying that the
capture_message("foo")
also doesn’t make it to Sentry? That is odd. I assumed you were only talking about theUnboundLocalError
.I’m afraid I don’t have enough experience with AWS to assist you in configuring the network of your setup. However, the lack of error when sending events is likely because we have a shutdown timeout of 2 seconds, which you are likely exceeding when the connection times out. If you increase this using
init(shutdown_timeout=999999)
you will likely see the error.We should improve those shutdown/flush debug messages.