I have a Flask / Celery app that uses a standard factory pattern (https://blog.miguelgrinberg.com/post/celery-and-the-flask-application-factory-pattern) but the errors from Celery tasks don’t send.
I have the debugging on and celery prints out a stack trace but the error isn’t reported.
INFO: event processor (<function DedupeIntegration.setup_once.<locals>.processor at 0x110c542f0>) dropped event ({'level': 'error', 'exception': {'values': [{'module': None, 'type': 'ZeroDivisionError', 'value': 'division by zero', 'mechanism': {'type': 'logging', 'handled': True}, 'stacktrace': {'frames': [{'filename': 'celery/app/trace.py', 'abs_path': '/anaconda3/lib/python3.6/site-packages/celery/app/trace.py', 'function': 'trace_task', 'module': 'celery.app.trace', 'lineno': 382, 'pre_context': [' request=task_request,', ' )', '', ' # -*- TRACE -*-', ' try:'], 'context_line': ' R = retval = fun(*args, **kwargs)', 'post_context': [' state = SUCCESS', ' except Reject as exc:', ' I, R = Info(REJECTED, exc), ExceptionInfo(internal=True)', ' state, retval = I.state, I.retval', ' I.handle_reject(task, task_request)'], 'vars': {}}, {'filename': '__init__.py', 'abs_path': '/Users/sethkillian/Projects/Classroom/Server/__init__.py', 'function': '__call__', 'module': 'Server', 'lineno': 53, 'pre_context': [' class ContextTask(TaskBase):', ' abstract = True', '', ' def __call__(self, *args, **kwargs):', ' with app.app_context():'], 'context_line': ' return TaskBase.__call__(self, *args, **kwargs)', 'post_context': ['', ' # def on_retry(self, exc, task_id, args, kwargs, einfo):', ' # """Log the exceptions to sentry at retry."""', ' # add_breadcrumb(', ' # task_id=task_id,'], 'vars': {}}, {'filename': 'celery/app/trace.py', 'abs_path': '/anaconda3/lib/python3.6/site-packages/celery/app/trace.py', 'function': '__protected_call__', 'module': 'celery.app.trace', 'lineno': 641, 'pre_context': [' stack = self.request_stack', ' req = stack.top', ' if req and not req._protected and \\', ' len(stack) == 1 and not req.called_directly:', ' req._protected = 1'], 'context_line': ' return self.run(*args, **kwargs)', 'post_context': [' return orig(self, *args, **kwargs)', ' BaseTask.__call__ = __protected_call__', ' BaseTask._stackprotected = True'], 'vars': {}}, {'filename': 'Server/tasks/test.py', 'abs_path': '/Users/sethkillian/Projects/Classroom/Server/tasks/test.py', 'function': 'divide_by_zero', 'module': 'Server.tasks.test', 'lineno': 9, 'pre_context': ['celery = create_celery_app()', '', '@celery.task()', 'def divide_by_zero():', ' """Task to test Error handling"""'], 'context_line': ' return 1 / 0', 'post_context': [], 'vars': {}}]}}]}, 'logger': 'celery.app.trace', 'logentry': {'message': 'Task %(name)s[%(id)s] %(description)s: %(exc)s', 'params': {'hostname': 'celery@Seths-MacBook-Pro-2.local', 'id': '159032d6-5692-4f1a-ab8d-17fe61c73a31', 'name': 'Server.tasks.test.divide_by_zero', 'exc': "ZeroDivisionError('division by zero',)", 'traceback': 'Traceback (most recent call last):\n File "/anaconda3/lib/python3.6/site-packages/celery/app/trace.py", line 382, in trace_task\n R = retval = fun(*args, **kwargs)\n File "/Users/sethkillian/Projects/Classroom/Server/__init__.py", line 53, in __call__\n return TaskBase.__call__(self, *args, **kwargs)\n File "/anaconda3/lib/python3.6/site-packages/celery/app/trace.py", line 641, in __protected_call__\n return self.run(*args, **kwargs)\n File "/anaconda3/lib/python3.6/site-packages/sentry_sdk/integrations/celery.py", line 118, in _inner\n reraise(*exc_info)\n File "/anaconda3/lib/python3.6/site-packages/sentry_sdk/_compat.py", line 52, in reraise\n raise value\n File "/anaconda3/lib/python3.6/site-packages/sentry_sdk/integrations/celery.py", line 113, in _inner\n return f(*args, **kwargs)\n File "/Users/sethkillian/Projects/Classroom/Server/tasks/test.py", line 9, in divide_by_zero\n return 1 / 0\nZeroDivisionError: division by zero\n', 'args': '[]', 'kwargs': '{}', 'description': 'raised unexpected', 'internal': False}}, 'extra': {'stack_info': None, 'data': {'hostname': 'celery@Seths-MacBook-Pro-2.local', 'id': '159032d6-5692-4f1a-ab8d-17fe61c73a31', 'name': 'Server.tasks.test.divide_by_zero', 'exc': "ZeroDivisionError('division by zero',)", 'traceback': 'Traceback (most recent call last):\n File "/anaconda3/lib/python3.6/site-packages/celery/app/trace.py", line 382, in trace_task\n R = retval = fun(*args, **kwargs)\n File "/Users/sethkillian/Projects/Classroom/Server/__init__.py", line 53, in __call__\n return TaskBase.__call__(self, *args, **kwargs)\n File "/anaconda3/lib/python3.6/site-packages/celery/app/trace.py", line 641, in __protected_call__\n return self.run(*args, **kwargs)\n File "/anaconda3/lib/python3.6/site-packages/sentry_sdk/integrations/celery.py", line 118, in _inner\n reraise(*exc_info)\n File "/anaconda3/lib/python3.6/site-packages/sentry_sdk/_compat.py", line 52, in reraise\n raise value\n File "/anaconda3/lib/python3.6/site-packages/sentry_sdk/integrations/celery.py", line 113, in _inner\n return f(*args, **kwargs)\n File "/Users/sethkillian/Projects/Classroom/Server/tasks/test.py", line 9, in divide_by_zero\n return 1 / 0\nZeroDivisionError: division by zero\n', 'args': '[]', 'kwargs': '{}', 'description': 'raised unexpected', 'internal': False}, 'asctime': '2019-07-08 18:49:30,486'}, 'event_id': '51a2bf7c90924f128b3a0aee272e272c', 'timestamp': datetime.datetime(2019, 7, 8, 22, 49, 30, 488472), 'breadcrumbs': [], 'contexts': {'trace': {'trace_id': 'e289f9e7e62e44f3a10e43ce102bab40', 'span_id': 'bed66685b8f5a12f'}}})
When I hit the error outside of Celery, there’s a line that says DEBUG: Sending error event...
but that never happens in Celery. It just goes straight to INFO: event processor...