I would like to add some Logger metadata to every Oban job process so Logger calls inside that process include the relevant metadata.
I am wondering if there is an easy way to do this other than manually calling Logger.metadata/1
at the beginning of each job process/1
function, which seems verbose and easy to forget or get out of sync between different jobs.
I think I’ve found a solution.
What I am doing is attaching to the [:oban, :job, :start]
telemetry event and setting the logger metadata in there. This makes it available for the process so anything that is logged from the job itself will include the relevant metadata.
def handle_event([:oban, :job, :start], _measures, %{job: job}, nil) do
Logger.metadata(RELEVANT_METADATA_INFORMATION)
end
6 Likes