Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django sentry default tags

I'm using python-raven to automatically capture all 500 in my django project, and it works great. I'm also forwarding some exceptions that I handle and append them with a special tag to be able to filter them out. The problem is that I can not filter for messages that is missing a particular tag so I'd like to set a default tag for all messages, but can't get it to work.

I've tried the following but it's just ignored.

RAVEN_CONFIG = {
    'dsn': 'udp://x:y@z:q/w',
    'tags': {'testtag': 'value'},
}

Does anyone know how to send a default tag to sentry?

like image 428
olofom Avatar asked Jul 13 '26 01:07

olofom


1 Answers

The following works for me in the settings module. It adds the environment variable DJANGO_ENVDIR to every message being sent.

from raven.contrib.django.client import DjangoClient as RavenDjangoClient
class SentryDjangoClient(RavenDjangoClient):
    def build_msg(self, *args, **kwargs):
        data = super(RavenDjangoClient, self).build_msg(*args, **kwargs)
        data['tags']['ENVDIR'] = os.environ.get('DJANGO_ENVDIR', 'unset')
        return data

if get_env_var('SENTRY_DSN', False):
    RAVEN_CONFIG = {
        'dsn': get_env_var('SENTRY_DSN'),
        # NOTE: timeout set via DSN
    }
    SENTRY_CLIENT = 'project.settings.base.SentryDjangoClient'

You need to adjust the SENTRY_CLIENT setting, according to where you put the SentryDjangoClient class, which extends the build_msg method.

like image 185
2 revsblueyed Avatar answered Jul 15 '26 13:07

2 revsblueyed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!