diff --git a/app/__init__.py b/app/__init__.py index d07cfc7eb0..02daa4b042 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -7,7 +7,6 @@ from flask_marshmallow import Marshmallow from flask_migrate import Migrate from time import monotonic -from ddtrace import patch from notifications_utils.clients.zendesk.zendesk_client import ZendeskClient from notifications_utils.clients.statsd.statsd_client import StatsdClient from notifications_utils.clients.redis.redis_client import RedisClient @@ -42,8 +41,6 @@ load_dotenv() -patch(celery=True) - migrate = Migrate() ma = Marshmallow() notify_celery = NotifyCelery() diff --git a/app/celery/celery.py b/app/celery/celery.py index 88e72af7c8..de5508a4da 100644 --- a/app/celery/celery.py +++ b/app/celery/celery.py @@ -3,6 +3,10 @@ from celery import Celery, Task from celery.signals import worker_process_shutdown, worker_shutting_down, worker_process_init from flask import current_app +from ddtrace import patch, tracer + +patch(celery=True) +current_app.logger.info('Celery has been patched with DataDog APM.') @worker_process_init.connect @@ -73,7 +77,8 @@ def __call__( # ensure task has flask context to access config, logger, etc with app.app_context(): self.start = time.time() - return super().__call__(*args, **kwargs) + with tracer.trace(self.name, service='celery-task'): + return super().__call__(*args, **kwargs) return NotifyTask