Skip to content

Commit

Permalink
Don't report empty stacktraces
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Apr 21, 2024
1 parent a3ae3c9 commit bed583f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
20 changes: 13 additions & 7 deletions lib/sentry/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,10 @@ defmodule Sentry.Event do

defp coerce_exception(exception, stacktrace_or_nil, _message, handled?)
when is_exception(exception) do
stacktrace =
if is_list(stacktrace_or_nil) do
%Interfaces.Stacktrace{frames: stacktrace_to_frames(stacktrace_or_nil)}
end

%Interfaces.Exception{
type: inspect(exception.__struct__),
value: Exception.message(exception),
stacktrace: stacktrace,
stacktrace: coerce_stacktrace(stacktrace_or_nil),
mechanism: %Interfaces.Exception.Mechanism{handled: handled?}
}
end
Expand All @@ -441,7 +436,7 @@ defmodule Sentry.Event do
defp add_thread_with_stacktrace(%__MODULE__{} = event, stacktrace) when is_list(stacktrace) do
thread = %Interfaces.Thread{
id: UUID.uuid4_hex(),
stacktrace: %Interfaces.Stacktrace{frames: stacktrace_to_frames(stacktrace)}
stacktrace: coerce_stacktrace(stacktrace)
}

%__MODULE__{event | threads: [thread]}
Expand All @@ -464,6 +459,17 @@ defmodule Sentry.Event do
|> create_event()
end

defp coerce_stacktrace(nil) do
nil
end

defp coerce_stacktrace(stacktrace) when is_list(stacktrace) do
case stacktrace_to_frames(stacktrace) do
[] -> nil
frames -> %Interfaces.Stacktrace{frames: frames}
end
end

defp stacktrace_to_frames(stacktrace) when is_list(stacktrace) do
in_app_module_allow_list = Config.in_app_module_allow_list()

Expand Down
2 changes: 1 addition & 1 deletion test/logger_backend_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule Sentry.LoggerBackendTest do
assert event.message.formatted =~ ~s<** (stop) bad return value: "I am throwing"\n>
assert event.message.formatted =~ ~s<Last message: {:"$gen_cast",>
assert event.message.formatted =~ ~s<State: []>
assert thread.stacktrace.frames == []
assert thread.stacktrace == nil
end

test "abnormal GenServer exit is reported" do
Expand Down
3 changes: 2 additions & 1 deletion test/sentry/logger_handler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ defmodule Sentry.LoggerHandlerTest do

if System.otp_release() >= "26" do
assert [] = event.exception
assert [_thread] = event.threads
assert [thread] = event.threads
assert thread.stacktrace == nil
assert event.extra.genserver_state == ":no_state"
assert event.extra.last_message =~ "{:run, #Function"
end
Expand Down

0 comments on commit bed583f

Please sign in to comment.