Sending Oban errors to Sentry via telemetry

Hey all!

We have some telemetry handlers set up to catch Oban errors and send them to Sentry. However, whenever an error does occur the telemetry handler seems to crash and detach. I’m not sure why. I’m assuming we’re doing something incorrectly in the handler.

Here’s our telemetry handler code.

def handle_event([:oban, :circuit, :trip], _measure, meta, _) do
  Sentry.capture_message(meta.error, stacktrace: meta.stacktrace, extra: meta)
end

def handle_event([:oban, :job, :exception], measure, meta, _) do
  extra = Map.take(meta, [:args, :id, :queue, :worker])
  extra = Map.merge(extra, measure)

  Sentry.capture_message(meta.error, stacktrace: meta.stacktrace, extra: extra)
end

Any ideas?

What version of Oban and what version of Sentry are you using? Since Oban 2.1 the meta.error value is always an exception, which should work correctly with Sentry.capture_exception.

1 Like

We’re using Oban 2.2.0 and Sentry 8.0.2.

Is there any reason why this would work.

Sentry.capture_exception(meta.error, stacktrace: meta.stacktrace, extra: meta)

and this wouldn’t

Sentry.capture_message(meta.error, stacktrace: meta.stacktrace, extra: meta)

?

From what I can see in sentry.ex the capture_message/2 variant requires a string and capture_exception/2 requires an exception.

1 Like

Thanks for the input! We’ll try that!

This worked! Thank you!

1 Like

Unrelated question. What would be a good way to filter out PerformError's in the telemetry instrumenter?

You can pattern match on the perform error, it is an exception struct:

  def handle_event([:oban, :job, :exception], _, %{error: %PerformError{}}, _), do: :ok
1 Like