Env:
raven working fine, trying to migrate to sentry-pythonOther seemingly related issues:
Code (simplified):
import sentry_sdk
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
sentry_sdk.init(
config.SENTRY_DSN,
debug=True,
integrations=[AwsLambdaIntegration()],
release=config.BUILD,
)
from zappa.async import task
@task
def send_sentry_message(): # pragma: no cover
sentry_sdk.capture_message("Test message from lambda worker")
try:
raise ExceptionTest("Fake exception to test exception handling in lambda worker")
except Exception:
sentry_sdk.capture_exception()
When I run send_sentry_message, nothing shows up in Sentry.
raven works fineI have a raven setup and a sentry-sdk running alongside. Messages sent by raven work fine, with the following configuration:
# in lib/sentry
from raven import Client
from raven.transport.http import HTTPTransport
from api.lib import config
client = Client(
dsn=config.SENTRY_DSN_WITH_SECRET_DEPRECATED,
processors=("raven.processors.SanitizePasswordsProcessor",),
release=config.BUILD,
raise_send_errors=True,
transport=HTTPTransport,
)
With debug=True, the logs look like this:
START RequestId: e050849e-0ec5-11e9-a95b-13339e6cd40a Version: $LATEST
Instancing..
[INFO] 2019-01-02T19:37:56.235Z e050849e-0ec5-11e9-a95b-13339e6cd40a Detected environment to be AWS Lambda. Using synchronous HTTP transport.
[sentry] DEBUG: Setting up integrations (with default = True)
[DEBUG] 2019-01-02T19:37:56.296Z e050849e-0ec5-11e9-a95b-13339e6cd40a Setting up integrations (with default = True)
[sentry] DEBUG: Setting up previously not enabled integration aws_lambda
[DEBUG] 2019-01-02T19:37:56.330Z e050849e-0ec5-11e9-a95b-13339e6cd40a Setting up previously not enabled integration aws_lambda
[sentry] DEBUG: Setting up previously not enabled integration logging
[DEBUG] 2019-01-02T19:37:56.330Z e050849e-0ec5-11e9-a95b-13339e6cd40a Setting up previously not enabled integration logging
[sentry] DEBUG: Setting up previously not enabled integration stdlib
[DEBUG] 2019-01-02T19:37:56.330Z e050849e-0ec5-11e9-a95b-13339e6cd40a Setting up previously not enabled integration stdlib
[sentry] DEBUG: Setting up previously not enabled integration excepthook
[DEBUG] 2019-01-02T19:37:56.330Z e050849e-0ec5-11e9-a95b-13339e6cd40a Setting up previously not enabled integration excepthook
[sentry] DEBUG: Setting up previously not enabled integration dedupe
[DEBUG] 2019-01-02T19:37:56.331Z e050849e-0ec5-11e9-a95b-13339e6cd40a Setting up previously not enabled integration dedupe
[sentry] DEBUG: Setting up previously not enabled integration atexit
[DEBUG] 2019-01-02T19:37:56.331Z e050849e-0ec5-11e9-a95b-13339e6cd40a Setting up previously not enabled integration atexit
[sentry] DEBUG: Setting up previously not enabled integration modules
[DEBUG] 2019-01-02T19:37:56.331Z e050849e-0ec5-11e9-a95b-13339e6cd40a Setting up previously not enabled integration modules
[sentry] DEBUG: Setting up previously not enabled integration argv
[DEBUG] 2019-01-02T19:37:56.331Z e050849e-0ec5-11e9-a95b-13339e6cd40a Setting up previously not enabled integration argv
[sentry] DEBUG: Enabling integration aws_lambda
[DEBUG] 2019-01-02T19:37:56.331Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration aws_lambda
[sentry] DEBUG: Enabling integration logging
[DEBUG] 2019-01-02T19:37:56.331Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration logging
[sentry] DEBUG: Enabling integration stdlib
[DEBUG] 2019-01-02T19:37:56.331Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration stdlib
[sentry] DEBUG: Enabling integration excepthook
[DEBUG] 2019-01-02T19:37:56.331Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration excepthook
[sentry] DEBUG: Enabling integration dedupe
[DEBUG] 2019-01-02T19:37:56.332Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration dedupe
[sentry] DEBUG: Enabling integration atexit
[DEBUG] 2019-01-02T19:37:56.332Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration atexit
[sentry] DEBUG: Enabling integration modules
[DEBUG] 2019-01-02T19:37:56.332Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration modules
[sentry] DEBUG: Enabling integration argv
[DEBUG] 2019-01-02T19:37:56.332Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration argv
[INFO] 2019-01-02T19:37:56.351Z e050849e-0ec5-11e9-a95b-13339e6cd40a Found credentials in environment variables.
[sentry] DEBUG: Setting up integrations (with default = True)
[DEBUG] 2019-01-02T19:37:56.509Z e050849e-0ec5-11e9-a95b-13339e6cd40a Setting up integrations (with default = True)
[sentry] DEBUG: Setting up previously not enabled integration flask
[DEBUG] 2019-01-02T19:37:56.509Z e050849e-0ec5-11e9-a95b-13339e6cd40a Setting up previously not enabled integration flask
[sentry] DEBUG: Enabling integration flask
[DEBUG] 2019-01-02T19:37:56.509Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration flask
[sentry] DEBUG: Enabling integration logging
[DEBUG] 2019-01-02T19:37:56.509Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration logging
[sentry] DEBUG: Enabling integration stdlib
[DEBUG] 2019-01-02T19:37:56.509Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration stdlib
[sentry] DEBUG: Enabling integration excepthook
[DEBUG] 2019-01-02T19:37:56.509Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration excepthook
[sentry] DEBUG: Enabling integration dedupe
[DEBUG] 2019-01-02T19:37:56.510Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration dedupe
[sentry] DEBUG: Enabling integration atexit
[DEBUG] 2019-01-02T19:37:56.510Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration atexit
[sentry] DEBUG: Enabling integration modules
[DEBUG] 2019-01-02T19:37:56.510Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration modules
[sentry] DEBUG: Enabling integration argv
[DEBUG] 2019-01-02T19:37:56.510Z e050849e-0ec5-11e9-a95b-13339e6cd40a Enabling integration argv
[INFO] 2019-01-02T19:37:56.650Z e050849e-0ec5-11e9-a95b-13339e6cd40a
{
"status": "starting",
"name": "send_sentry_message",
"event": "lambda task",
"logger": "api.task.base",
"level": "info",
"timestamp": "2019-01-02T19:37:56.649991Z"
}
[INFO] 2019-01-02T19:37:56.672Z e050849e-0ec5-11e9-a95b-13339e6cd40a
{
"status": "done",
"name": "send_sentry_message",
"event": "lambda task",
"logger": "api.task.base",
"level": "info",
"timestamp": "2019-01-02T19:37:56.672028Z"
}
Result of zappa.async.route_lambda_task:
null
END RequestId: e050849e-0ec5-11e9-a95b-13339e6cd40a
REPORT RequestId: e050849e-0ec5-11e9-a95b-13339e6cd40a Duration: 11075.88 ms Billed Duration: 11100 ms Memory Size: 512 MB Max Memory Used: 138 MB
The only thing I see is that it's activating the flask plugin even though it's not used in this context, but looking at the flask plugin code, it shouldn't impact sending the message.
Happy to dig more based on your feedback.
Ah, yes I think we simply don't support that part of zappa yet. You can get around this by running this inside of your task:
with init(...):
...
capture_exception()
Then exiting the contextmanager will wait until the event has been sent
A workaround is documented at: https://docs.sentry.io/platforms/python/serverless/
Thanks!
I need to test this together with some custom scope tags.
That's a good point, the decorator should push a new scope. I forgot to do
that.
On Thu, Feb 21, 2019, 19:26 Charles-Axel Dein notifications@github.com
wrote:
Thanks!
I need to test this together with some custom scope tags.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/getsentry/sentry-python/issues/227#issuecomment-466110892,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAzHxfZsVdjP3INMKb3Dlz3knwxgZCcRks5vPuS-gaJpZM4ZnIFP
.
I am using Django and zappa seems to be working fine for me using sentry_sdk. I switched from raven setup because it didn't work for me.
anybody who uses aws lambda and does not receive events... could you try bumping shutdown_timeout to a larger number?
init(..., shutdown_timeout=20) # event sending must not take longer than 20 seconds, default 2
@untitaker I am using Zappa + Flask and can confirm that setting the shutdown_timeout=20 does not fix the problem. I tried this:
sentry_sdk.init(
dsn=os.getenv('SENTRY_DSN'),
integrations=[FlaskIntegration()],
shutdown_timeout=20
)
I was able to work around this issue by decorating all of my functions with the @serverless_function decorator.
@jasonrhaas you need to enable the AwsLamdbaIntegration as well. Then the workaround should not be necessary/
Cool, this worked:
sentry_sdk.init(
dsn=os.getenv('SENTRY_DSN'),
integrations=[FlaskIntegration(), AwsLambdaIntegration()]
)
Most helpful comment
Cool, this worked: