question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CeleryIntegration wrongly reporting errors for tasks with custom __call__ method

See original GitHub issue

Environment

How do you use Sentry? Sentry SaaS (sentry.io)

Which SDK and version? Python 1.1.0

Steps to Reproduce

  1. Create a custom celery base task class
  2. Implement a custom __call__ method on that base task class
  3. Catch and handle certain exceptions in that __call__ method
  4. Raise a different exception from the custom __call__ method

Example code:

from celery import Task

class CustomBaseTask(Task):
    def __call__(self, *args, **kwargs):
        try:
            super().__call__(*args, **kwargs)
        except CustomExceptionA:
            # do sth
            raise SpecialException()
        except CustomExceptionB:
            pass


@shared_task(base=CustomBaseTask, bind=True)
def some_actual_task(self, ...):
   ...  # do sth here

Expected Result

  • Errors caught in the custom __call__ method should not be sent to sentry (i.e., CustomExceptionA, CustomExceptionB)
  • Errors raised in the custom __call__ method should be sent to sentry (i.e., SpecialException)

Actual Result

  • CustomExceptionA and CustomExceptionB are shown by sentry as unhandled (although in fact they are as our other monitoring systems confirm)
  • SpecialException is never shown in sentry, although it is being raised (confirmed by our other monitoring systems)

From debugging it seems that sentry wraps the task’s run method, which is called by the celery.Task.__call__ method and thus at a lower level than the custom call method.

Also it seems that sentry’s attempted wrap of the task’s __call__ method is not working, since SpecialException is never sent to sentry.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
antonpirkercommented, Feb 28, 2022

Quick update: I am looking into this

0reactions
github-actions[bot]commented, Apr 12, 2022

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone … forever!


“A weed is but an unloved flower.” ― Ella Wheeler Wilcox 🥀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Version 0.17.8 broke Celery tasks with custom Task class #844
I am using tenant-schemas-celery package, which generates it's own TenantTask (extends celery.app.task.Task) class in it's own CeleryApp ...
Read more >
Celery - error handling and data storage - Stack Overflow
I see that results have statuses/states and stores results if requested -- when would I use this data? Should error handling and data...
Read more >
Celery Documentation - Read the Docs
To call our task you can use the delay() method. ... Errors in this list will be reported as a failure to the...
Read more >
Release Notes — ddtrace documentation
django: handle erroneous middleware gracefully. The tracer now captures the task ID from the cgroups file for Fargate >= 1.4.0 and reports it...
Read more >
Custom Fields | sticky.io Help Center
A contact custom field will allow values to be stored in the field ... delete the incorrect custom field and restart the creation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found