Celery
The Celery integration adds support for the Celery Task Queue System.
Just add CeleryIntegration()
to your integrations
list:
import sentry_sdk
from sentry_sdk.integrations.celery import CeleryIntegration
sentry_sdk.init(
dsn='https://examplePublicKey@o0.ingest.sentry.io/0',
integrations=[CeleryIntegration()]
)
Additionally, the Sentry Python SDK will set the transaction on the event to the task name, and it will improve the grouping for global Celery errors such as timeouts.
The integration will automatically report errors from all celery jobs.
Generally, make sure that the call to init
is loaded on worker startup, and not only in the module where your tasks are defined. Otherwise, the initialization happens too late and events might end up not being reported.
Note on distributed tracing
Sentry uses custom message headers for distributed tracing. Since Celery version 4.0, for message protocol of version 1, this functionality is broken and Celery fails to propagate custom headers to the worker. Protocol version 2, which is default since Celery version 4.0, is not affected.
Fix for the custom headers propagation issue was introduced to Celery project (PR) and hopefully will be included in the upcoming release.
- Package:
- pypi:sentry-sdk
- Version:
- 0.19.5
- Repository:
- https://github.com/getsentry/sentry-python