Sentry integration with wsgi

I have Plone5.2rc3 and I want to integrate sentry. But with wsgi there is no "event-log-custom" anymore (see: https://pypi.org/project/plone.recipe.zope2instance/).

Am I missing a newer documenation? How can I integrate sentry now?

According to the sentry documentation, there is an official middleware

To see if this is working I locally changed Zope2/Startup/serve.py:"https://github.com/zopefoundation/Zope/blob/master/src/Zope2/Startup/serve.py#L189" and added

        import sentry_sdk
        from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
        sentry_sdk.init(dsn="https://8d99f3b243284563a450522f31cab1e1@mysentry/2")
        app = SentryWsgiMiddleware(app)

after line 182. It is working but no good way to add sentry.

Are there already plans for a better integration of sentry?

If im not wrong.. sentry can just work throught logger (exceptions) just add it to your initialize.. I thought I had to monkey patch something from it related to zlog and utf8 (but this can also be related to our old zope installation).
if you are interested i can share the snippets to get it running.

1 Like

if you are interested i can share the snippets to get it running.

That would be great - thx.

1 Like

I am also looking into options for performing a proper Sentry integration for Plone 5.2 under WSGI.

One approach was already mentioned by wrapping app within the run() method.

I should also be possible configuring Sentry through a custom logger configuration in your wsgi.ini and/or as a WSGI filter as part of your WSGI pipeline in your wsgi.ini.

Unfortunately my WSGI know-how at this time is very limited in order to determine what the best option would be.

An integration with Zope/Plone must be provide some more information beside what Sentry gets out of Python by itself. The former raven.contrib.zope integration with was used in Zope 2 e.g. extracts the request information, the user information and some additional HTTP related information like HTTP headers etc.

See raven-python/raven/contrib/zope/__init__.py at master · getsentry/raven-python · GitHub

So a new Sentry integration must get hold of these data as well.

Here is the first result of my new Sentry integration with Zope 4/Plone 5.2.
It's heavily based on the former raven.contrib.zope module and supports logging of the request headers and user information.

3 Likes