opbeat_python icon indicating copy to clipboard operation
opbeat_python copied to clipboard

Attach extra data to exceptions

Open blueyed opened this issue 8 years ago • 0 comments

It is possible to provide extra information when logging:

logger.error(e, exc_info=True, extra={'key': value})

But I could not find a documented way to do so with exceptions?

It seems to work through a custom capture method (via settings.OPBEAT['CLIENT']):

class OpbeatDjangoClient(opbeat.contrib.django.DjangoClient):
    def capture(self, event_type, request=None, **kwargs):
        kwargs.setdefault(
            'extra', {})['some_setting'] = settings.SOME_SETTING

        if event_type == 'Exception':
            if 'exc_info' in kwargs:
                exc_value = kwargs['exc_info'][1]
                if hasattr(exc_value, 'opbeat_extra'):
                    for k, v in exc_value.opbeat_extra.items():
                        kwargs['extra'][k] = v
        return super().capture(event_type, request, **kwargs)

Would this be something to handle in a generic way via opbeat.events.Exception.capture?

blueyed avatar Jul 26 '17 13:07 blueyed