Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ defmodule ErrorTrackerDevWeb.PageController do
<div><a href="/404">Generate Router 404</a></div>
<div><a href="/noroute">Raise NoRouteError from a controller</a></div>
<div><a href="/exception">Generate Exception</a></div>
<div><a href="/exit">Generate Exit</a></div>
""")
end

Expand All @@ -70,6 +71,10 @@ defmodule ErrorTrackerDevWeb.PageController do
raise "This is a controller exception"
end

def call(_conn, :exit) do
exit(:timeout)
end

defp content(conn, content) do
conn
|> put_resp_header("content-type", "text/html")
Expand Down Expand Up @@ -100,6 +105,7 @@ defmodule ErrorTrackerDevWeb.Router do
get "/", ErrorTrackerDevWeb.PageController, :index
get "/noroute", ErrorTrackerDevWeb.PageController, :noroute
get "/exception", ErrorTrackerDevWeb.PageController, :exception
get "/exit", ErrorTrackerDevWeb.PageController, :exit
end
end

Expand Down
12 changes: 6 additions & 6 deletions lib/error_tracker/integrations/phoenix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ defmodule ErrorTracker.Integrations.Phoenix do
end

def handle_event([:phoenix, :router_dispatch, :exception], _measurements, metadata, :no_config) do
{reason, stack} =
{reason, kind, stack} =
case metadata do
%{reason: %Plug.Conn.WrapperError{reason: reason, stack: stack}} ->
{reason, stack}
%{reason: %Plug.Conn.WrapperError{reason: reason, kind: kind, stack: stack}} ->
{reason, kind, stack}

%{reason: reason, stacktrace: stack} ->
{reason, stack}
%{kind: kind, reason: reason, stacktrace: stack} ->
{reason, kind, stack}
end

PlugIntegration.report_error(metadata.conn, reason, stack)
PlugIntegration.report_error(metadata.conn, {reason, kind}, stack)
end
end
2 changes: 1 addition & 1 deletion lib/error_tracker/integrations/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ defmodule ErrorTracker.Integrations.Plug do
catch
kind, reason ->
stack = __STACKTRACE__
unquote(__MODULE__).report_error(conn, reason, stack)
unquote(__MODULE__).report_error(conn, {kind, reason}, stack)

:erlang.raise(kind, reason, stack)
end
Expand Down
16 changes: 14 additions & 2 deletions lib/error_tracker/schemas/error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,21 @@ defmodule ErrorTracker.Error do
def new(exception, stacktrace = %ErrorTracker.Stacktrace{}) do
source = ErrorTracker.Stacktrace.source(stacktrace)

{kind, reason} =
case exception do
%struct{} = ex when is_exception(ex) ->
{to_string(struct), Exception.message(ex)}

{_kind, %struct{} = ex} when is_exception(ex) ->
{to_string(struct), Exception.message(ex)}

{kind, ex} ->
{to_string(kind), to_string(ex)}
end

params = [
kind: "error",
reason: Exception.message(exception),
kind: to_string(kind),
reason: reason,
source_line: "#{source.file}:#{source.line}",
source_function: "#{source.module}.#{source.function}/#{source.arity}"
]
Expand Down