[Django]-Django sentry default tags

-1👍

After looking into it a bit more it seems like this is not at all possible ATM.

👤olofom

8👍

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.

0👍

You could assign a different name to the logger, before logging the message. That would allow you to filter by the “logger” in the Sentry server.

Leave a comment