Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Websocket with flask dont work with sentry #953

Open
ratasxy opened this issue Feb 9, 2017 · 1 comment
Open

Websocket with flask dont work with sentry #953

ratasxy opened this issue Feb 9, 2017 · 1 comment

Comments

@ratasxy
Copy link

ratasxy commented Feb 9, 2017

Hi,

I have a web socket using flask, gevent and SocketIO, I'm trying integrate Sentry but the websocket stops working

my websocker runner is like it:

monkey.patch_all()

if __name__ == '__main__':
    print ('Listening on http://127.0.0.1:%s and on port XXXX '
           '(flash policy server)' % WEBSOCKET_PORT)
    SocketIOServer(('', WEBSOCKET_PORT), app,
                   resource="socket.io").serve_forever()

and my sentry integration is similar to:

from raven.contrib.flask import Sentry

monkey.patch_all()
app = Flask(__name__)
app.debug = True

sentry = Sentry(app, dsn=RAVEN_WEBSOCKETS_DSN)

I tried use GEVENT TRANSPORT https://docs.sentry.io/clients/python/transports/#gevent but still not working.

@malthejorgensen
Copy link

I'm not sure Sentry automatically registers for the SocketIO part of the app (it does for the Flask part).

I got it to with some manual setup:

from flask import current_app

app = create_app()

# Setup Sentry
if 'SENTRY_DSN_SOCKETIO' in app.config:
    app.sentry = Client(app.config['SENTRY_DSN_SOCKETIO'], transport=GeventedHTTPTransport)

socketio = SocketIO(app)

@socketio.on_error_default
def grasp_default_error_handler(e):
    # Report to Sentry
  current_app.sentry.captureException()

This is assuming you're using Flask-SocketIO.
I'm not sure it's currently possible to intercept exceptions in pure python-socketio (See: miguelgrinberg/python-socketio#45 (comment))

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants