Skip to content

Special-case Ranch errors in the logger handler for OTP 25 #818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/sentry/logger_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ defmodule Sentry.LoggerHandler do

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

# Special-case Ranch messages because their formatting is their formatting.
%{format: ~c"Ranch listener ~p" ++ _, args: args} ->
capture_from_ranch_error(args, sentry_opts, config)

_ ->
capture(:message, inspect(report), sentry_opts, config)
end
Expand Down Expand Up @@ -587,6 +591,28 @@ defmodule Sentry.LoggerHandler do
capture(:message, string_message, sentry_opts, config)
end

# This is only causing issues on OTP 25 apparently.
# TODO: remove special-cased Ranch handling when we depend on OTP 26+.
defp capture_from_ranch_error(
_args = [
_listener,
_connection_process,
_stream,
_request_process,
_reason = {{exception, stacktrace}, _}
],
sentry_opts,
%__MODULE__{} = config
)
when is_exception(exception) do
sentry_opts = Keyword.merge(sentry_opts, stacktrace: stacktrace, handled: false)
capture(:exception, exception, sentry_opts, config)
end

defp capture_from_ranch_error(args, sentry_opts, %__MODULE__{} = config) do
capture(:message, "Ranch listener error: #{inspect(args)}", sentry_opts, config)
end

defp add_extra_to_sentry_opts(sentry_opts, new_extra) do
Keyword.update(sentry_opts, :extra, %{}, &Map.merge(new_extra, &1))
end
Expand Down