oban-bg / oban

💎 Robust job processing in Elixir, backed by modern PostgreSQL and SQLite3
https://oban.pro
Apache License 2.0
3.37k stars 313 forks source link

Jobs that exit with `{:error, ...` are logged at `info` level. #1125

Closed jozuas closed 3 months ago

jozuas commented 3 months ago

Environment

Current Behavior

defmodule Tp.Smth do
  use Oban.Worker,
    queue: :testing,
    max_attempts: 1

  @impl Oban.Worker
  def perform(%Oban.Job{args: _args}) do
    {:error, "sample error message"}
  end
end

Produces the log at info level

18:15:45.963 pid=<0.923.0>  [info] {"error":"** (Oban.PerformError) Tp.Smth failed with {:error, \"sample error message\"}","args":{},"id":159,"meta":{},"state":"discard","max_attempts":1,"queue":"testing","worker":"Tp.Smth","source":"oban","attempt":1,"tags":[],"duration":3141,"event":"job:exception","queue_time":27019}

Expected Behavior

Produces the log at error level

18:15:45.963 pid=<0.923.0>  [error] {"error":"** (Oban.PerformError) Tp.Smth failed with {:error, \"sample error message\"}","args":{},"id":159,"meta":{},"state":"discard","max_attempts":1,"queue":"testing","worker":"Tp.Smth","source":"oban","attempt":1,"tags":[],"duration":3141,"event":"job:exception","queue_time":27019}
sorentwo commented 3 months ago

The default logger outputs all events at the same level. Many error handlers (e.g. Sentry, HoneyBadger, AppSignal) will automatically report for any message at the error level, and they'll also use telemetry info to report Oban errors.

The logger is built on telemetry data, so you can build a custom logger with various levels if desired.