server-tools icon indicating copy to clipboard operation
server-tools copied to clipboard

Sentry update using sentry-sdk + reducing complexity

Open lastalfriday opened this issue 3 years ago • 5 comments

The old sentry python lib is deprecated: https://github.com/getsentry/raven-python

I've played around with the new and semi-kind-of got it working, but cannot manage to hook into the odoo exception system https://docs.sentry.io/platforms/python/guides/wsgi/

Here's my setup.

import sentry_sdk
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
from odoo.service import wsgi_server

from sentry_sdk import capture_message

sentry_sdk.init(
    "https://xxxx",
    traces_sample_rate=1.0,
    debug=True,
)
sentry_sdk.set_level('debug')

wsgi_server.application = SentryWsgiMiddleware(wsgi_server.application)

This is pretty straight forward, except that my knownledge is limited so I cannot get this working property, but it seems the current (https://github.com/OCA/server-tools/tree/14.0/sentry) is more complex than it needs to be?

Thanks

lastalfriday avatar Feb 11 '22 19:02 lastalfriday

Update: I pretty much got this up and working fine. My issues earlier was that exceptions didn't reach Sentry when triggering them from UI actions. But that seemed to be because Odoo somehow "eats" these up. Any other exceptions are sent to Sentry.

The setup is super easy and is basically just this

# -*- coding: utf-8 -*-
from odoo.tools import config
from odoo.service import wsgi_server
# https://docs.sentry.io/platforms/python/
import sentry_sdk
# https://docs.sentry.io/platforms/python/guides/wsgi/
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware

sentry_dsn = config.get('sentry_dsn')
if sentry_dsn:
    sentry_sdk.init(
        dsn=sentry_dsn,
        environment=config.get('sentry_environment', 'unknown'),
        # debug=True,
    )
    sentry_sdk.set_level('error')

    wsgi_server.application = SentryWsgiMiddleware(wsgi_server.application)

KISS :)

fractalf avatar Feb 15 '22 13:02 fractalf

Hi @fractalf !

Where did you add this code? I added that snippet on init.py file of my custom module but it doesn't work :(

Thanks!

adriancuero avatar Jun 10 '22 20:06 adriancuero

@adriancuero Hi, I just made a new file sentry.py and included it in the manifest file, then upgrade module in Odoo

fractalf avatar Jun 13 '22 09:06 fractalf

There is a pending PR, which seems to work fine. Check it out #2254

schiggi avatar Jun 22 '22 23:06 schiggi

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.

github-actions[bot] avatar Apr 27 '25 12:04 github-actions[bot]