Skip to content

Commit

Permalink
Add args to LOG_RECEIVED (fixes celery#6885) (celery#6898)
Browse files Browse the repository at this point in the history
* Add args and kwargs to LOG_RECEIVED and LOG_SUCCESS

* Add kwargs and args to test
  • Loading branch information
daveisfera authored and jeyrce committed Aug 25, 2021
1 parent 5065323 commit 2168efe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions celery/app/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ def trace_task(uuid, args, kwargs, request=None):
'name': get_task_name(task_request, name),
'return_value': Rstr,
'runtime': T,
'args': safe_repr(args),
'kwargs': safe_repr(kwargs),
})

# -* POST *-
Expand Down
8 changes: 7 additions & 1 deletion celery/worker/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging

from kombu.asynchronous.timer import to_timestamp
from kombu.utils.encoding import safe_repr

from celery import signals
from celery.app import trace as _app_trace
Expand Down Expand Up @@ -151,7 +152,12 @@ def task_message_handler(message, body, ack, reject, callbacks,
if _does_info:
# Similar to `app.trace.info()`, we pass the formatting args as the
# `extra` kwarg for custom log handlers
context = {'id': req.id, 'name': req.name}
context = {
'id': req.id,
'name': req.name,
'args': safe_repr(req.args),
'kwargs': safe_repr(req.kwargs),
}
info(_app_trace.LOG_RECEIVED, context, extra={'data': context})
if (req.expires or req.id in revoked_tasks) and req.revoked():
return
Expand Down
2 changes: 1 addition & 1 deletion t/unit/worker/test_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_log_task_received_custom(self, caplog):
C()
for record in caplog.records:
if record.msg == custom_fmt:
assert set(record.args) == {"id", "name"}
assert set(record.args) == {"id", "name", "kwargs", "args"}
break
else:
raise ValueError("Expected message not in captured log records")
Expand Down

0 comments on commit 2168efe

Please sign in to comment.