Can I help with some integrations?
@kasamsharif absolutely. If you have something that is missing and you want it to be there feel free to send a pull request.
Hello
what needs to be done for aws lambda integration ?
if you could give me an idea where to start , I'm very interested in trying to implement it and making a PR.
we need something like this https://docs.sentry.io/platforms/javascript/node/?platform=node to force the waiting period of 2s before the lambda shuts down ?
@bendidi Does this help? https://docs.sentry.io/learn/draining/?platform=python
For AWS Lambda, it is more about the transporter is default to be using threaded background worker and we need something like the HTTPTransporter (non-threaded) in the old raven library that could send the exception right away synchronously.
@cowcow02 we understand, but @bendidi was specifically asking about the shutdown timeout. We currently don't support aws lambda.
As @bendidi was asking what needs to do for AWS lambda integration so provided a bit of information I know here :-)
I was trying to upgrade my Zappa-powered Flask app on AWS Lambda with the new SDK and noticed the issue as well.
@cowcow02 we will have a look at lambda but I don't quite see why the default threaded transport is not sufficient there. Are atexit handlers not called on lambda? We do flush out on shutdown.
@untitaker I've tested using :
client = Hub.current.client
if client is not None:
client.close(timeout=2.0)
right before the lambda finished it's task, but still no error is reported by sentry !
@bendidi using this inside of the lambda function like this works for me:
import sentry_sdk
def my_handler():
with sentry_sdk.init(...):
try:
raise ValueError()
except:
sentry_sdk.capture_exception()
raise
However, hopefully we will have a proper integration soon.
Closing for #74 and #75
@bendidi @cowcow02 0.3.5 is out with AWS lamdba integration. See https://github.com/getsentry/sentry-docs/pull/380 for docs
@bendidi @cowcow02 0.3.5 is out with AWS lamdba integration. See getsentry/sentry-docs#380 for docs
@untitaker brilliant! let me try with the Zappa + Flask to see if things are working fine in this combination 馃憤
@cowcow02 note you likely need both Flask and AWS integrations for it to work.
Right now we only test raw AWS without Zappa or Flask, let me know if you encounter issues with combining flask and lambda
If I have enough time I will try out both Flask + Lambda & Django + Lambda, as the two primary frameworks we uses on Serverless + Python. Let me get back to here when I have the result.
more info: for raven it was working pretty well for Django+Zappa (when HTTPTransporter is on), and for Flask+Zappa is more tricky with some missing exception I never managed to make it works. Hope this time I could manage to make it working perfectly ;-)
@cowcow02 we will have a look at lambda but I don't quite see why the default threaded transport is not sufficient there. Are atexit handlers not called on lambda? We _do_ flush out on shutdown.
To be frank I ain't quite sure why threaded transport is not working there as well, as the threading module was supported by AWS Lambda itself. As I am using Zappa on top of AWS Lambda together, it could be either one of them not giving the shutdown signal to raven properly so it never got flushed? Anyways I will simply be trying out the new integration to see how it goes :-)
@cowcow02 no worries, we internally figured out why AWS lambda wasn't working right. Didn't have anything to do with threads, it's just that AWS kills or suspends the process as soon as it considers the request done.
The integration should take care of it.
I just finished my testing and found that Zappa-based Flask applications will not be able to boot up with the AwsLambdaIntegration
I tested the integration with the following setup:
sentry-sdk==0.3.7 with both FlaskIntegration and AwsLambdaIntegration includedAnd here is the minimal code to test:
# -*- coding: utf-8 -*-
import os
import sentry_sdk
from flask import Flask, jsonify
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
from sentry_sdk.integrations.flask import FlaskIntegration
app = Flask(__name__)
sentry_sdk.init(
dsn=os.environ.get('sentry_dsn'),
integrations=[
FlaskIntegration(),
AwsLambdaIntegration()
]
)
@app.route('/exception_test', methods=['GET'])
def exception_test():
raise Exception('this is an Exception that expected to catch')
@app.route('/error_test', methods=['GET'])
def error_test():
error = 1 / 0
return jsonify({
'error': error
})
if __name__ == "__main__":
app.run()
When I try to boot up the Flask app, the following error will be returned:
AttributeError: module '__main__' has no attribute 'make_final_handler'
@cowcow02 So I just tested this and the aws_lambda integration definetly doesn't work under Zappa (in the sense that events go missing). I haven't been able to reproduce the exact exception you encountered. Could you add the following to your code (at module level, before init is called):
import __main__ as foo
print(foo.__file__)
print(dir(foo))
Also if you have the time I would apprechiate if you could give me a zipfile I can upload to Lambda to reproduce your issue. Basically, strip down your app s.t. you can still reproduce the issue, then run zappa package and give me the created zipfile.
Sure, let me provide the minimal setup project demo tmr to illustrate the issue. Thanks!
I ain't sure where to put this snippet so I decided to attach the whole minimal demo source code here:
my-demo-project-source.zip
And here is the result from zappa package: my-demo-project-dev-1538559115.zip
hmm, I can't reproduce anything like the error message you're seeing:
AttributeError: module '__main__' has no attribute 'make_final_handler'
but anyway I'll release a new version fixing the errorhandling issues with Zappa
@cowcow02 so since reproducing it with your zipfile didn't work, could you deploy with the two print-statements I posted earlier and give me their output? I am not too familiar with this entire ecosystem but I assume they'll end up in zappa tail?
I am closing this since a lot has happened since then and the issue with AWS Lambda is likely resolved
Most helpful comment
@cowcow02 no worries, we internally figured out why AWS lambda wasn't working right. Didn't have anything to do with threads, it's just that AWS kills or suspends the process as soon as it considers the request done.
The integration should take care of it.