Skip to content

Commit

Permalink
Appsignal.Transaction.set_error/4 handles unformatted stacktraces (#72)
Browse files Browse the repository at this point in the history
* Transaction.set_error/4 handles unformatted stacktraces

* Don't format_stack/1 in Phoenix.submit_http_error/5
  • Loading branch information
jeffkreeftmeijer authored and Arjan Scherpenisse committed Jan 13, 2017
1 parent f139277 commit bca9991
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/appsignal/phoenix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ defmodule Appsignal.Phoenix do

@doc false
def submit_http_error(reason, message, stack, transaction, conn) do
Transaction.set_error(transaction, reason, message, ErrorHandler.format_stack(stack))
Transaction.set_error(transaction, reason, message, stack)
Transaction.try_set_action(transaction, conn)
if Transaction.finish(transaction) == :sample do
Transaction.set_request_metadata(transaction, conn)
Expand Down
8 changes: 8 additions & 0 deletions lib/appsignal/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ defmodule Appsignal.Transaction do
"""
@spec set_error(Transaction.t | nil, String.t, String.t, any) :: Transaction.t
def set_error(nil, _name, _message, _backtrace), do: nil
def set_error(%Transaction{} = transaction, name, message, [h|_] = backtrace) when is_tuple(h) do
set_error(
transaction,
name,
message,
Appsignal.ErrorHandler.format_stack(backtrace)
)
end
def set_error(%Transaction{} = transaction, name, message, backtrace) do
name = name |> String.split_at(@max_name_size) |> elem(0)
backtrace_data = Appsignal.Utils.DataEncoder.encode(backtrace)
Expand Down
7 changes: 7 additions & 0 deletions test/transaction/transaction_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,11 @@ defmodule AppsignalTransactionTest do
assert ^transaction = Transaction.start_event(transaction)
assert ^transaction = Transaction.finish_event(transaction, "phoenix_controller_render", "phoenix_controller_render", %{format: "html", template: "index.html"}, 0)
end

test "handles unformatted stacktraces" do
transaction = Transaction.start("test1", :http_request)
assert ^transaction = Transaction.set_error(transaction, "Error", "error message", System.stacktrace)
assert ^transaction = Transaction.start_event(transaction)
assert ^transaction = Transaction.finish_event(transaction, "phoenix_controller_render", "phoenix_controller_render", %{format: "html", template: "index.html"}, 0)
end
end

0 comments on commit bca9991

Please sign in to comment.