Using Sentry - errors, or all messages? ; Logging versus captureMessage/captureException?

5,143 views
Skip to first unread message

Victor Hooi

unread,
Oct 16, 2013, 4:27:59 AM10/16/13
to gets...@googlegroups.com
Hi,

Should we be using Sentry just to log errors/exceptions?

Or is it also a useful tool for logging general information messages from your application?

This blog post:


seems to imply that Disqus uses it for errors only.

Secondly, for a vanilla Python script, is it better to just hook into the normal logging module:


rather than explicitly calling client.captureMessage() or client.captureException()?

Finally - how exactly do you specify the level for something like captureMessage() - I couldn't seem to find it mentioned in the docs.

Cheers,
Victor

David Cramer

unread,
Oct 17, 2013, 1:22:13 AM10/17/13
to gets...@googlegroups.com
Hi Victor

You don’t want to use it for general logging (it provides no value, and is extremely expensive for that kind of operation).

We do recommend abstracting it through something like logging, which is how we do it ourselves. When we do that we simply say “only errors go to the SentryHandler”.

Regarding level on captureMessage, its just an argument. That said, you should consider level a legacy thing, as it’s just a tag in Sentry and no longer something that heavily describes an event.
--
You received this message because you are subscribed to the Google Groups "sentry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to getsentry+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Victor Hooi

unread,
Oct 22, 2013, 9:56:33 PM10/22/13
to gets...@googlegroups.com
Hi,

Cool, that helps clear some things up, thanks =).

So based on here:


and raven/conf/__init__.py, I should do:

from raven.handlers.logging import SentryHandler
client = Sentry(...)
setup_logging(SentryHandler(client))

And then after that, I  can use logging.get_logger(), and whenever I call logger.error(), it will pass to Sentry?

Or I can just put client.captureException() into my exception handling code. (Or am I better off using logger.error('There was an error, with a stacktrace!', exc_info=True) ?)

I noticed that the handler only seems to capture error-level messages. I'm just curious where that's configured?

I couldn't seem to find that explicitly set in SetupHandler - I thought it takes it from a kwarg in SetupHandler, but I can't see that being set anywhere so I thought it would fall back to NOTSET?

Or is it somehow related to?


Cheers,
Victor

David Cramer

unread,
Oct 22, 2013, 9:58:05 PM10/22/13
to gets...@googlegroups.com
setup_logging configures the minimum log level to send to SentryHandler (since e.g. DEBUG messages are absolutely useless)

You can use either approach, though most sane people would say that abstracting it via logging is probably a better idea.

Victor Hooi

unread,
Oct 22, 2013, 11:03:32 PM10/22/13
to gets...@googlegroups.com
Hi,

Sorry, I may have been wrong before, it was actually passing through all logging levels.

I didn't realise level was an argument for SentryHandler (it's not in the docs, is it?).

Anyhow, now I have:

def setup_raven(config):
    logger = logging.getLogger('sync_bex')
    try:
        global client
        client = Client(config['sentry']['dsn'])
        setup_logging(SentryHandler(client, level=logging.ERROR))
    except ValueError as e:
        logger.error('Uhoh - please check your Sentry DSN - %s' % e)

which will only pass ERROR and up to Sentry.

Cheers,
Victor
Reply all
Reply to author
Forward
0 new messages