Skip to content
This repository has been archived by the owner on Jun 11, 2018. It is now read-only.

Recipe: Capture exceptions during celery/kombu's serialization #179

Open
michael-k opened this issue Aug 11, 2017 · 0 comments
Open

Recipe: Capture exceptions during celery/kombu's serialization #179

michael-k opened this issue Aug 11, 2017 · 0 comments

Comments

@michael-k
Copy link

michael-k commented Aug 11, 2017

Example for pickle; works similar for JSON, YAML, …

def capture_serialization_exceptions():
    from pickle import dumps

    from kombu import serialization
    from kombu.exceptions import DecodeError
    from opbeat.contrib.django.models import client

    def loads(s):
        try:
            return serialization.unpickle(s)
        except LookupError as e:
            client.capture_exception()
            raise
        except DecodeError as e:
            client.capture_exception()
            raise
        except Exception as e:
            client.capture_exception()
            raise

    # See https://github.com/celery/kombu/blob/v3.0.37/kombu/serialization.py#L342-L360
    serialization.register(
        name='my_pickle',
        encoder=dumps,
        decoder=loads,
        content_type='application/x-python-serialize',
        content_encoding='binary',
    )

I did not figure out where to put this. If you can point me to a file, I'm happy to open a PR.

LookupError` might be enough, but we did not care enough to investigate. If someone from opbeat wants to see a logged example (closed source project; with a LookupError), I'm happy to provide a link via email.

We call the functions when doing https://opbeat.com/docs/articles/get-started-with-django/#logging-celery-tasks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant