Oban telemetry event `[:oban, :engine, :discard_job, :exception]` not emitted

It says in the Oban documentation that a [:oban, :engine, :discard_job, :start | :stop | :exception] is emitted by the Oban library,

I attach an event handler

      [
        "oban-job-discard-handler",
        [:oban, :engine, :discard_job, :exception],
        &handle_job_discard/4,
        %{}
      ] 
      |> Enum.each(fn [handler_id, event_name, function, config] ->
        :telemetry.attach(handler_id, event_name, function, config)
      end)

But it seems like that event is never emitted by Oban, am I missing something? Any help would be much appreciated :slight_smile:

The :discard_job event is only triggered by direct Engine calls. You can handle discards with [:oban, :job, :exception].

Side note; if you’re handling multiple events, use :telemetry.attach_many :slightly_smiling_face:

1 Like

hey @sorentwo thanks for getting back to me, and the attach_many tip.

In regards to the [:oban, :job, :exception] event, can I differentiate between the jobs that fail/throw an exception, and those who’s retry attempts have expired ?

Best,
Camille

The state field will indicate if it was an error, or if it was the final error and the job is being discarded. There’s information about all the fields in the Job Events section.

2 Likes