Skip to content

Commit a14e3f8

Browse files
authored
Special-case Ranch errors in the logger handler for OTP 25 (#818)
1 parent 568186c commit a14e3f8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/sentry/logger_handler.ex

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ defmodule Sentry.LoggerHandler do
361361

362362
capture(:message, "** (stop) #{Exception.format_exit(reason)}", sentry_opts, config)
363363

364+
# Special-case Ranch messages because their formatting is their formatting.
365+
%{format: ~c"Ranch listener ~p" ++ _, args: args} ->
366+
capture_from_ranch_error(args, sentry_opts, config)
367+
364368
_ ->
365369
capture(:message, inspect(report), sentry_opts, config)
366370
end
@@ -587,6 +591,28 @@ defmodule Sentry.LoggerHandler do
587591
capture(:message, string_message, sentry_opts, config)
588592
end
589593

594+
# This is only causing issues on OTP 25 apparently.
595+
# TODO: remove special-cased Ranch handling when we depend on OTP 26+.
596+
defp capture_from_ranch_error(
597+
_args = [
598+
_listener,
599+
_connection_process,
600+
_stream,
601+
_request_process,
602+
_reason = {{exception, stacktrace}, _}
603+
],
604+
sentry_opts,
605+
%__MODULE__{} = config
606+
)
607+
when is_exception(exception) do
608+
sentry_opts = Keyword.merge(sentry_opts, stacktrace: stacktrace, handled: false)
609+
capture(:exception, exception, sentry_opts, config)
610+
end
611+
612+
defp capture_from_ranch_error(args, sentry_opts, %__MODULE__{} = config) do
613+
capture(:message, "Ranch listener error: #{inspect(args)}", sentry_opts, config)
614+
end
615+
590616
defp add_extra_to_sentry_opts(sentry_opts, new_extra) do
591617
Keyword.update(sentry_opts, :extra, %{}, &Map.merge(new_extra, &1))
592618
end

0 commit comments

Comments
 (0)