# Buggy code
def event_processor(event, hint):
    with capture_internal_exceptions():
        event["transaction"] = task.name

    with capture_internal_exceptions():
        extra = event.setdefault("extra", {})
        extra["celery-job"] = {
            "task_name": task.name,
            "args": args,
            "kwargs": kwargs,
        }

    if "exc_info" in hint:
        with capture_internal_exceptions():
            if isinstance(hint["exc_info"][1], Retry):
                return None

            if hasattr(task, "throws") and isinstance(hint["exc_info"][1], task.throws):
                return None

        with capture_internal_exceptions():
            if issubclass(hint["exc_info"][0], SoftTimeLimitExceeded):
                event["fingerprint"] = [
                    "celery",
                    "SoftTimeLimitExceeded",
                    getattr(task, "name", task),
                ]

    return event


# Traceback (RuntimeError)
[2019-03-08 21:24:21,117: ERROR/ForkPoolWorker-31] Task simple_task[d6e959b1-7253-4e55-861d-c1968ae14e1c] raised unexpected: RuntimeError('No active exception to reraise')
Traceback (most recent call last):
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/celery/app/trace.py", line 382, in trace_task
R = retval = fun(*args, **kwargs)
File "/Users/okomarov/Documents/repos/myproject/web/celery_factory.py", line 28, in __call__
return TaskBase.__call__(self, *args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/celery/app/trace.py", line 641, in __protected_call__
return self.run(*args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 66, in _inner
reraise(*_capture_exception())
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/_compat.py", line 52, in reraise
raise value
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 64, in _inner
return f(*args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 66, in _inner
reraise(*_capture_exception())
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/_compat.py", line 52, in reraise
raise value
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 64, in _inner
return f(*args, **kwargs)
File "/Users/okomarov/Documents/repos/myproject/web/simple_task.py", line 4, in simple_task
raise Exception("Testing Celery exception")
RuntimeError: No active exception to reraise

# Fixed code
def event_processor(event, hint):
    with capture_internal_exceptions():
        event["transaction"] = task.name

    with capture_internal_exceptions():
        extra = event.setdefault("extra", {})
        extra["celery-job"] = {
            "task_name": task.name,
            "args": args,
            "kwargs": kwargs,
        }

    if "exc_info" in hint:
        with capture_internal_exceptions():
            if issubclass(hint["exc_info"][0], SoftTimeLimitExceeded):
                event["fingerprint"] = [
                    "celery",
                    "SoftTimeLimitExceeded",
                    getattr(task, "name", task),
                ]

    return event