Skip to content

Commit 9d3c7f5

Browse files
authored
feat(taskworker) Make status codes easier to understand (#92224)
Metric tags with named labels are much easier to understand than integer values.
1 parent 4acc527 commit 9d3c7f5

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/sentry/taskworker/workerchild.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ def get_at_most_once_key(namespace: str, taskname: str, task_id: str) -> str:
8383
return f"tw:amo:{namespace}:{taskname}:{task_id}"
8484

8585

86+
def status_name(status: TaskActivationStatus.ValueType) -> str:
87+
"""Convert a TaskActivationStatus to a human readable name"""
88+
if status == TASK_ACTIVATION_STATUS_COMPLETE:
89+
return "complete"
90+
if status == TASK_ACTIVATION_STATUS_FAILURE:
91+
return "failure"
92+
if status == TASK_ACTIVATION_STATUS_RETRY:
93+
return "retry"
94+
return f"unknown-{status}"
95+
96+
8697
def child_process(
8798
child_tasks: queue.Queue[TaskActivation],
8899
processed_tasks: queue.Queue[ProcessingResult],
@@ -334,15 +345,15 @@ def record_task_execution(
334345
"taskname": activation.taskname,
335346
"execution_duration": execution_duration,
336347
"execution_latency": execution_latency,
337-
"status": status,
348+
"status": status_name(status),
338349
},
339350
)
340351
metrics.incr(
341352
"taskworker.worker.execute_task",
342353
tags={
343354
"namespace": activation.namespace,
344355
"taskname": activation.taskname,
345-
"status": status,
356+
"status": status_name(status),
346357
"processing_pool": processing_pool_name,
347358
},
348359
)

0 commit comments

Comments
 (0)