From 025b51c801d0c7aad2d84de9ac9b54da401106d6 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 21 Dec 2020 14:53:14 +0000 Subject: [PATCH] If the request_id exists in the Flask global context, add it to the kwargs for the task. The request_id is set is the task is created from a http request, if that task then calls through to another task this will set the request_id from the global context. We should then be able to follow the creation of a notification all the way from the original http request to the sending task. --- app/celery/celery.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/celery/celery.py b/app/celery/celery.py index 76e4f464e..0316a61b8 100644 --- a/app/celery/celery.py +++ b/app/celery/celery.py @@ -58,6 +58,8 @@ def make_task(app): if has_request_context() and hasattr(request, 'request_id'): kwargs['request_id'] = request.request_id + elif g.request_id: + kwargs['request_id'] = g.request_id with SQS_APPLY_ASYNC_DURATION_SECONDS.labels(self.name).time(): return super().apply_async(args, kwargs, task_id, producer, link, link_error, **options)