Skip to content

Commit

Permalink
feat: reports whether exception was handled/unhandled
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Dec 17, 2024
1 parent 2fe1bab commit 870c3b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
22 changes: 14 additions & 8 deletions lib/tower_sentry/sentry/event.ex
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
defmodule TowerSentry.Sentry.Event do
@moduledoc false

def from_tower_event(%Tower.Event{
kind: :error,
reason: exception,
stacktrace: stacktrace,
id: id,
plug_conn: plug_conn,
metadata: metadata
}) do
def from_tower_event(
%Tower.Event{
kind: :error,
reason: exception,
stacktrace: stacktrace,
id: id,
plug_conn: plug_conn,
metadata: metadata
} = event
) do
put_environment_name()

Sentry.Event.create_event(
exception: exception,
stacktrace: stacktrace,
handled: manual_report?(event),
request: request_data(plug_conn),
user: user_data(metadata),
extra: %{id: id, metadata: metadata}
Expand Down Expand Up @@ -120,4 +123,7 @@ defmodule TowerSentry.Sentry.Event do
Application.fetch_env!(:tower_sentry, :environment_name)
)
end

defp manual_report?(%{by: nil}), do: true
defp manual_report?(_), do: false
end
15 changes: 9 additions & 6 deletions test/tower_sentry_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ defmodule TowerSentryTest do
%{
"type" => "ArithmeticError",
"value" => "bad argument in arithmetic expression",
"stacktrace" => %{"frames" => frames}
"stacktrace" => %{"frames" => frames},
"mechanism" => %{"handled" => false}
} = exception
)

assert(
%{
"function" => ~s(anonymous fn/0 in TowerSentryTest."test reports arithmetic error"/1),
"filename" => "test/tower_sentry_test.exs",
"lineno" => 67
"lineno" => 68
} = List.last(frames)
)

Expand Down Expand Up @@ -96,7 +97,7 @@ defmodule TowerSentryTest do
%{
"function" => ~s(anonymous fn/0 in TowerSentryTest."test reports throw"/1),
"filename" => "test/tower_sentry_test.exs",
"lineno" => 112
"lineno" => 113
} = List.last(frames)
)

Expand Down Expand Up @@ -141,7 +142,7 @@ defmodule TowerSentryTest do
%{
"function" => ~s(anonymous fn/0 in TowerSentryTest."test reports abnormal exit"/1),
"filename" => "test/tower_sentry_test.exs",
"lineno" => 157
"lineno" => 158
} = List.last(frames)
)

Expand Down Expand Up @@ -191,7 +192,8 @@ defmodule TowerSentryTest do
%{
"type" => "ArithmeticError",
"value" => "bad argument in arithmetic expression",
"stacktrace" => %{"frames" => frames}
"stacktrace" => %{"frames" => frames},
"mechanism" => %{"handled" => false}
} = exception
)

Expand Down Expand Up @@ -358,7 +360,8 @@ defmodule TowerSentryTest do
%{
"type" => "ArithmeticError",
"value" => "bad argument in arithmetic expression",
"stacktrace" => %{"frames" => frames}
"stacktrace" => %{"frames" => frames},
"mechanism" => %{"handled" => false}
} = exception
)

Expand Down

0 comments on commit 870c3b3

Please sign in to comment.