-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from beligante/add-crash-report-to-error-log
[ 377 ] Add `crash_report` logger metadata for exceptions captured by `Cowboy.Handler`
- Loading branch information
Showing
4 changed files
with
84 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule GRPC.Logger do | ||
@doc """ | ||
Normalizes the exception and stacktrace inputs by its kind to match the format specified for `crash_report` metadata | ||
in [Logger](https://hexdocs.pm/logger/main/Logger.html#module-metadata) | ||
""" | ||
def crash_reason(:throw, reason, stacktrace), do: {{:nocatch, reason}, stacktrace} | ||
def crash_reason(:error, reason, stack), do: {Exception.normalize(:error, reason, stack), stack} | ||
def crash_reason(:exit, reason, stacktrace), do: {reason, stacktrace} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule GRPC.Server.Adapters.ReportException do | ||
@moduledoc """ | ||
Exception raised by server adapter, meant to be used as part of metadata `crash_report` | ||
""" | ||
|
||
defexception [:kind, :reason, :stack, :adapter_extra] | ||
|
||
def new(adapter_extra, %{__exception__: _} = exception, stack \\ [], kind \\ :error) do | ||
exception(kind: kind, reason: exception, stack: stack, adapter_extra: adapter_extra) | ||
end | ||
|
||
def message(%__MODULE__{adapter_extra: [{:req, req}], kind: kind, reason: reason, stack: stack}) do | ||
# Cowboy adapter message builder | ||
path = :cowboy_req.path(req) | ||
"Exception raised while handling #{path}:\n" <> Exception.format_banner(kind, reason, stack) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters