Include metadata in sidekiq jobs
Spun out of gitlab-com/gl-infra/production#1028 (closed)
When we are experiencing issues related to Sidekiq queues, it can be quite difficult to correlate the issue with a particular user, project or namespace.
It would be useful if, when emitting structured logs for Sidekiq events, we could include some meta-data such as the user who invoked the job, the project the job is related to etc.
Obviously not all jobs have these fields, but when they do, it would be useful to include these values.
Before
{
"severity":"INFO",
"time":"2019-08-05T14:16:27.894Z",
"class":"NewNoteWorker",
"args":["200144415"],
"retry":3,
"queue":"new_note",
"jid":"f7bd388f608e5fd4de46c6c2",
"created_at":"2019-08-05T11:17:58.171Z",
"correlation_id":"TEN7oNvplx4",
"enqueued_at":"2019-08-05T11:17:58.175Z",
"pid":17779,
"message":"NewNoteWorker JID-f7bd388f608e5fd4de46c6c2: done: 716.241 sec",
"job_status":"done",
"duration":716.241,
"completed_at":"2019-08-05T14:16:27.894Z",
"tag":"sidekiq",
"environment":"gprd",
"hostname":"sidekiq-asap-02-sv-gprd",
"fqdn":"sidekiq-asap-02-sv-gprd.c.gitlab-production.internal"
}
After
{
"severity":"INFO",
"time":"2019-08-05T14:16:27.894Z",
"class":"NewNoteWorker",
"args":["200144415"],
"retry":3,
"queue":"new_note",
"jid":"f7bd388f608e5fd4de46c6c2",
"created_at":"2019-08-05T11:17:58.171Z",
"correlation_id":"TEN7oNvplx4",
"enqueued_at":"2019-08-05T11:17:58.175Z",
"pid":17779,
"message":"NewNoteWorker JID-f7bd388f608e5fd4de46c6c2: done: 716.241 sec",
"job_status":"done",
"duration":716.241,
"completed_at":"2019-08-05T14:16:27.894Z",
"tag":"sidekiq",
"environment":"gprd",
"hostname":"sidekiq-asap-02-sv-gprd",
"fqdn":"sidekiq-asap-02-sv-gprd.c.gitlab-production.internal",
"meta": {
"user": "andrewn",
"gl_project_path": "andrewn/andrewn"
"gl_toplevel_namespace": "andrewn"
}
}
Edited by Andrew Newdigate