Repository navigation
Closed
Labels
Milestone
Description
Checklist
- I have checked the issues list
for similar or identical enhancement to an existing feature. - I have checked the pull requests list
for existing proposed enhancements. - I have checked the commit log
to find out if the same enhancement was already implemented in the
main branch. - I have included all related issues and possible duplicate issues in this issue
(If there are none, check this box anyway).
Related Issues and Possible Duplicates
Related Issues
- None
Possible Duplicates
- None
Brief Summary
When a task is called with apply_async, the request has root_id & parent_id which helps in tracing the logs.
But when a task is executed with apply, the root_id & parent_id are missing from the request.
We are using the root_id to club logs of a root-task. but for applied tasks, its not working.
I understand, we are not adding a task to queue when it's called with apply, because we run locally... but adding the root-id & parent-id will help regardless.
Details
We are using the following formatter:
(
'{"ts": "%(asctime)s", "log_level": "%(levelname)s", "process_name":'
' "%(processName)s", "file": "%(filename)s:%(lineno)d", "task_name":'
' "%(task_name)s", "task_id": "%(task_id)s", "root_id":'
' "%(root_id)s", "parent_id": "%(parent_id)s", "msg": "%(message)s"}'
)
This works, because we add the properties before formatting the logs
class CustomFormatter(TaskFormatter):
def format(self, record):
task = get_current_task()
if task and task.request:
record.__dict__.update(
task_id=task.request.id,
task_name=task.name,
parent_id=task.request.parent_id or "",
root_id=task.request.root_id or "",
)
else:
record.__dict__.setdefault("task_name", "")
record.__dict__.setdefault("task_id", "")
record.__dict__.setdefault("parent_id", "")
record.__dict__.setdefault("root_id", "")
return super().format(record)
Activity
tests: (celery#9738) root_id and parent_id for .apply()
Fix celery#9738 : Add root_id and parent_id to .apply() (celery#9784)