The Celery integration adds support for the Celery Task Queue System.
CeleryIntegration() to your
import sentry_sdk from sentry_sdk.integrations.celery import CeleryIntegration sentry_sdk.init( dsn='https://examplePublicKey@o0.ingest.sentry.io/0', integrations=[ CeleryIntegration(), ], # Set traces_sample_rate to 1.0 to capture 100% # of transactions for performance monitoring. # We recommend adjusting this value in production, traces_sample_rate=1.0, )
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.
If you're using Celery standalone, there are two ways to set this up:
Initializing the SDK in the configuration file loaded with Celery's
import sentry_sdk from celery import Celery, signals app = Celery("myapp") #@signals.worker_init.connect @signals.celeryd_init.connect def init_sentry(**_kwargs): sentry_sdk.init(dsn="...")
If you're using Celery with Django in a conventional setup, have already initialized the SDK in your
settings.py file, and have Celery using the same settings with
config_from_object, you don't need to initialize the SDK separately for Celery.
To verify if your SDK is initialized on worker start, you can pass
debug=True to see extra output when the SDK is initialized. If the output appears during worker startup and not only after a task has started, then it's working properly.