Question

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?

Was it helpful?

Solution 3

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

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top