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.

[celery integration] before_send function executed twice

See original GitHub issue

Doing a simple test with sentry and celery integration I see the function before_send gets executed twice when an exception is raised while the on_failure celery task mechanism gets executed correctly once.

Setup:

    # within my make_celery() function to create the celery app

    def before_send(event, hint):
        print('before_send celery integration')
        return event

    sentry_sdk.init(dsn=url, integrations=[CeleryIntegration(), SqlalchemyIntegration()], before_send=before_send)

on_failure celery callback handler

def on_failure(task, exc, task_id, args, _, exception_info, **__):
    logger.error("on_failure error print")

celery task:

@celery.task(bind=True, name="test_sentry_integration", on_failure=on_failure, ignore_result=True)
def test_sentry_integration(_, message):
    raise Exception(message)

output:

[2019-11-15 11:02:13,148: WARNING/ForkPoolWorker-1] test the sdk
[2019-11-15 11:02:13,152: WARNING/ForkPoolWorker-1] before_send celery integration
2019-11-15 11:02:13,159::comfortmanager.common.tasks::ERROR::on_failure error print
[2019-11-15 11:02:13,161: WARNING/ForkPoolWorker-1] before_send celery integration
[2019-11-15 11:02:13,161: ERROR/ForkPoolWorker-1] Task test_sentry_integration[2f5848b3-1e12-4a0d-92e2-0b4dec63e7c8] raised unexpected: Exception('test the sdk',)

Versions:

celery 4.3.0
sentry-sdk 0.13.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
untitakercommented, Nov 15, 2019

level controls creation of breadcrumbs (that is, writing them into a local “scrollback” buffer) and event_level controls creation of events. So yes, the INFO logs may appear in the event. However, we wipe breadcrumbs between celery tasks and between HTTP requests (depending on framework), and the buffer is per-thread. So they should be somewhat related to the crash.

0reactions
untitakercommented, Nov 15, 2019

Glad to be of help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Task is executed twice when the worker restarts #4426 - GitHub
I've increased processes on my virtual machine, and celery created worker with concurrency of 2(had 1 before).
Read more >
Task gets executed twice when a view runs first time
As I can see in logs, celery worker is receiving this task twice: ... when I open the same url, there's only one...
Read more >
Celery beat causes task to run twice - Google Groups
I have a celery setup inside a django app. Celery version is 3.1.23. Earlier I was running celery beat inside the worker using...
Read more >
Release Notes — Airflow Documentation
Permission to view Airflow Configurations has been removed from User and Viewer role; Default [celery] worker_concurrency is changed to 16 ...
Read more >
celery.app.task — Celery 5.2.7 documentation
Please note that this means the task may be executed twice if the worker crashes mid execution. The application default can be overridden...
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