diff --git a/src/sentry/taskworker/workerchild.py b/src/sentry/taskworker/workerchild.py index 59cce3ef70dc9b..2d53ddf5c45d47 100644 --- a/src/sentry/taskworker/workerchild.py +++ b/src/sentry/taskworker/workerchild.py @@ -162,7 +162,6 @@ def handle_alarm(signum: int, frame: FrameType | None) -> None: while True: if max_task_count and processed_task_count >= max_task_count: - metrics.incr( "taskworker.worker.max_task_count_reached", tags={"count": processed_task_count, "processing_pool": processing_pool_name}, @@ -176,9 +175,16 @@ def handle_alarm(signum: int, frame: FrameType | None) -> None: logger.info("taskworker.worker.shutdown_event") break + child_tasks_get_start = time.monotonic() try: + # If the queue is empty, this could block for a second. inflight = child_tasks.get(timeout=1.0) except queue.Empty: + metrics.distribution( + "taskworker.worker.child_task_queue_empty.wait_duration", + time.monotonic() - child_tasks_get_start, + tags={"processing_pool": processing_pool_name}, + ) metrics.incr( "taskworker.worker.child_task_queue_empty", tags={"processing_pool": processing_pool_name},