Skip to content

How can we set this correlation_id in celery if we call .apply() to trigger a task? #90

Closed Answered by lukehsiao
lukehsiao asked this question in Q&A
Discussion options

You must be logged in to vote

Was able to solve this by just providing headers= to the .apply() call and grabbing that in

@task_prerun.connect()
def load_correlation_id(task) -> None:
    # This is called when the worker picks up the task
    # Here we're able to load the correlation ID from the headers
    id_value = task.request.get(header_key)
    correlation_id.set(id_value)

However, note that we needed to use task.request.headers.get rather than task.request.get directly.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sondrelg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant