GithubHelp home page GithubHelp logo

Comments (26)

untitaker avatar untitaker commented on May 3, 2024 2

@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.

untitaker avatar untitaker commented on May 3, 2024 2

@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.

cowcow02 avatar cowcow02 commented on May 3, 2024 1

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.

untitaker avatar untitaker commented on May 3, 2024 1

@Bendidi @cowcow02 0.3.5 is out with AWS lamdba integration. See getsentry/sentry-docs#380 for docs

from sentry-python.

untitaker avatar untitaker commented on May 3, 2024 1

@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.

kasimsharif avatar kasimsharif commented on May 3, 2024

Can I help with some integrations?

from sentry-python.

mitsuhiko avatar mitsuhiko commented on May 3, 2024

@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.

obendidi avatar obendidi commented on May 3, 2024

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.

untitaker avatar untitaker commented on May 3, 2024

@Bendidi Does this help? https://docs.sentry.io/learn/draining/?platform=python

from sentry-python.

cowcow02 avatar cowcow02 commented on May 3, 2024

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.

untitaker avatar untitaker commented on May 3, 2024

@cowcow02 we understand, but @Bendidi was specifically asking about the shutdown timeout. We currently don't support aws lambda.

from sentry-python.

mitsuhiko avatar mitsuhiko commented on May 3, 2024

@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.

obendidi avatar obendidi commented on May 3, 2024

@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.

untitaker avatar untitaker commented on May 3, 2024

Closing for #74 and #75

from sentry-python.

untitaker avatar untitaker commented on May 3, 2024

https://docs.sentry.io/platforms/python/aws_lambda

from sentry-python.

cowcow02 avatar cowcow02 commented on May 3, 2024

@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.

cowcow02 avatar cowcow02 commented on May 3, 2024

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 avatar cowcow02 commented on May 3, 2024

@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.

cowcow02 avatar cowcow02 commented on May 3, 2024

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:

  1. Created an empty Flask application
  2. Installed sentry-sdk==0.3.7 with both FlaskIntegration and AwsLambdaIntegration included
  3. 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.

untitaker avatar untitaker commented on May 3, 2024

@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.

untitaker avatar untitaker commented on May 3, 2024

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.

cowcow02 avatar cowcow02 commented on May 3, 2024

Sure, let me provide the minimal setup project demo tmr to illustrate the issue. Thanks!

from sentry-python.

cowcow02 avatar cowcow02 commented on May 3, 2024

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.

untitaker avatar untitaker commented on May 3, 2024

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.

untitaker avatar untitaker commented on May 3, 2024

@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.

untitaker avatar untitaker commented on May 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.