Comments (26)
@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.
from sentry-python.
@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.
from sentry-python.
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.
from sentry-python.
@Bendidi @cowcow02 0.3.5 is out with AWS lamdba integration. See getsentry/sentry-docs#380 for docs
from sentry-python.
@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
from sentry-python.
Can I help with some integrations?
from sentry-python.
@kasamsharif absolutely. If you have something that is missing and you want it to be there feel free to send a pull request.
from sentry-python.
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 ?
from sentry-python.
@Bendidi Does this help? https://docs.sentry.io/learn/draining/?platform=python
from sentry-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.
Ref: getsentry/raven-python#1063
from sentry-python.
@cowcow02 we understand, but @Bendidi was specifically asking about the shutdown timeout. We currently don't support aws lambda.
from sentry-python.
@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.
from sentry-python.
@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 !
from sentry-python.
from sentry-python.
https://docs.sentry.io/platforms/python/aws_lambda
from sentry-python.
@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 👍
from sentry-python.
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 ;-)
from sentry-python.
@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 :-)
from sentry-python.
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:
- Created an empty Flask application
- Installed
sentry-sdk==0.3.7
with bothFlaskIntegration
andAwsLambdaIntegration
included - Deployed the Flask application to AWS Lambda with Zappa
And 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'
from sentry-python.
@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))
from sentry-python.
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.
from sentry-python.
Sure, let me provide the minimal setup project demo tmr to illustrate the issue. Thanks!
from sentry-python.
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
from sentry-python.
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
from sentry-python.
@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
?
from sentry-python.
I am closing this since a lot has happened since then and the issue with AWS Lambda is likely resolved
from sentry-python.
Related Issues (20)
- [Crons] Connection closing due to a timeout causing failed monitors HOT 2
- Internal error in sentry_sdk HOT 11
- Performance monitoring for streaming responses
- Fastapi: Url with path param without replacement in profiles_sampler and/or before_send_transaction HOT 4
- AWS Lambda failing w/ RuntimeError: can't start new thread on 1.40.3 HOT 1
- Make EventScrubber recursive HOT 3
- Auto instrumented Celery tasks have mismatching environment values between the first and second check-ins HOT 4
- Python metrics cause transaction duration changes
- Hubs & Scopes missing tasks HOT 3
- Cron monitor check-in fails due to backend errors in event flushing HOT 9
- Sentry doesn't support loguru level=trace HOT 1
- Instructions in `CONTRIBUTING.md` lead to an incomplete environment HOT 2
- SDK stuck in processing RecursionError:maximum recursion depth exceeded events HOT 1
- GrapheneIntegration: Enhance Transaction Naming for Errors in Graphene GraphQL Operations HOT 5
- Cronjob monitoring isn't very ergonomic if you're not using an automatic integration HOT 4
- ImportWarning caused by integrations on Python 3.10 HOT 1
- Add file name and line number to logentry
- uWSGI worker throwing Runtime Exception when run with `py-call-uwsgi-fork-hooks` flag HOT 3
- Make `pytest-sentry` compatible to Sentry SDK 2.0
- Update all integrations to use the new Scope API and document it HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sentry-python.