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.
This commit is contained in:
Rebecca Law
2020-12-21 14:53:14 +00:00
parent 2749a707f2
commit 025b51c801

View File

@@ -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)