Browse Source

Change celery task logger output (#47)

Casper van der Wel 11 months ago
parent
commit
0a34f43e37

+ 2 - 0
CHANGES.md

@@ -6,6 +6,8 @@
 
 - Use a timeout for fetching jwks in TokenVerifier.
 
+- Changed celery task logger args/kwargs back to argsrepr/kwargsrepr.
+
 
 0.9.3 (2023-12-04)
 ------------------

+ 6 - 6
clean_python/celery/celery_task_logger.py

@@ -82,14 +82,14 @@ class CeleryTaskLogger:
             correlation_id = None
 
         try:
-            args = json.loads(json.dumps(request.args))
+            argsrepr = json.dumps(request.args)
         except (AttributeError, TypeError):
-            args = None
+            argsrepr = None
 
         try:
-            kwargs = json.loads(json.dumps(kwargs))
+            kwargsrepr = json.dumps(kwargs)
         except TypeError:
-            kwargs = None
+            kwargsrepr = None
 
         log_dict = {
             "tag_suffix": "task_log",
@@ -100,8 +100,8 @@ class CeleryTaskLogger:
             "duration": duration,
             "origin": getattr(request, "origin", None),
             "retries": getattr(request, "retries", None),
-            "args": args,
-            "kwargs": kwargs,
+            "argsrepr": argsrepr if argsrepr != "null" else None,
+            "kwargsrepr": kwargsrepr if kwargsrepr != "null" else None,
             "result": result_json,
             "tenant_id": tenant_id,
             "correlation_id": None if correlation_id is None else str(correlation_id),

+ 3 - 2
integration_tests/test_int_celery.py

@@ -1,3 +1,4 @@
+import json
 import time
 from uuid import UUID
 
@@ -74,8 +75,8 @@ def test_log_success(celery_task: BaseTask, task_logger: CeleryTaskLogger):
     assert log["state"] == "SUCCESS"
     assert log["name"] == "testing"
     assert log["duration"] > 0.0
-    assert log["args"] == [0.0]
-    assert log["kwargs"] == {"return_value": 16}
+    assert json.loads(log["argsrepr"]) == [0.0]
+    assert json.loads(log["kwargsrepr"]) == {"return_value": 16}
     assert log["retries"] == 0
     assert log["result"] == {"value": 16}
     assert UUID(log["correlation_id"])  # generated

+ 4 - 4
tests/celery/test_celery_task_logger.py

@@ -24,8 +24,8 @@ def test_log_minimal(celery_task_logger: CeleryTaskLogger):
         "state": "STAAT",
         "duration": None,
         "origin": None,
-        "args": None,
-        "kwargs": None,
+        "argsrepr": None,
+        "kwargsrepr": None,
         "result": None,
         "time": None,
         "tenant_id": None,
@@ -73,8 +73,8 @@ def test_log_with_request(celery_task_logger: CeleryTaskLogger, celery_task):
     assert entry["name"] == "task_name"
     assert entry["task_id"] == "abc123"
     assert entry["retries"] == 25
-    assert entry["args"] == [1, 2]
-    assert entry["kwargs"] == {}
+    assert entry["argsrepr"] == "[1, 2]"
+    assert entry["kwargsrepr"] == "{}"
     assert entry["origin"] == "hostname"
     assert entry["correlation_id"] == "b3089ea7-2585-43e5-a63c-ae30a6e9b5e4"