[11.x] Add --json flag to queue:work command for structured logging #52887
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
This PR introduces a new
--jsonflag for thequeue:workcommand, enabling structured JSON output for enhanced observability.Motivation
Why not?
Monolog\Formatter\JsonFormatter.JSON output format
The JSON output continues to include two log entries per job: one at the start and another at completion.
Key fields include:
timestamp: Datetime in ISO 8601 format.level: PSR-3 log levelinfoorwarning. It helps monitoring tools.status: Current execution status ofqueue:workcommand:starting,success,released_after_exceptionorfailed.result: Outcome of completed jobs:deleted,releasedorfailed.duration: In seconds.exception: FQCN of the Exception.message: Exception message.Sucessful Job
{ "timestamp": "2024-09-23T13:47:37.347077+00:00", "level": "info", "job": "App\\Jobs\\NotificarJob", "id": "9af01732-609a-4418-86f3-904f928fd8cc", "uuid": "88098a41-4a1e-4ea6-a4f0-58511f91e915", "connection": "rabbitmq", "queue": "default", "status": "success", "result": "deleted", "attempts": 1, "duration": 0.014354 }Failed Job
{ "timestamp": "2024-09-23T13:44:57.393616+00:00", "level": "warning", "job": "App\\Jobs\\TestJob", "id": "12c2916c-6a04-40d7-b0d8-c48897c425a0", "uuid": "7e719912-f6c2-4018-a1c2-c7254992f182", "connection": "rabbitmq", "queue": "default", "status": "failed", "result": "deleted", "attempts": 3, "exception": "App\\Exceptions\\TestException", "message": "I have failed you.", "duration": 0.001601 }Job Starting
{ "timestamp": "2024-09-23T13:48:37.593466+00:00", "level": "info", "job": "App\\Jobs\\ConsultarEnvioDocumentoAReguladorJob", "id": "e600e9dd-474b-4e18-ad5e-a3cadd3b04c9", "uuid": "e76cd7c8-1754-48e7-9b45-5a7ea8664d53", "connection": "rabbitmq", "queue": "regulador", "status": "starting", "attempts": 2 }Open Questions
-vargument to control the verbosity of the JSON output?