Skip to content

Commit

Permalink
feat: workaround for missing Logger messages
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Feb 10, 2025
1 parent 260a1bc commit 4ee84d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/tower_error_tracker/reporter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ defmodule TowerErrorTracker.Reporter do
:ok
end

def report_event(%Tower.Event{kind: :message, reason: reason, level: level} = event) do
message = "[#{level}] #{reason}"
ErrorTracker.report({"message #{:erlang.phash2(message)}", message}, [], context(event))

:ok
end

def report_event(_event) do
:ignore
end
Expand Down
15 changes: 13 additions & 2 deletions test/tower_error_tracker_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ defmodule TowerErrorTrackerTest do
)
end

test "Logger messages not reported because not supported by ErrorTracker" do
test "Logger messages reported as special custom exceptions (because messages not supported by ErrorTracker)" do
in_unlinked_process(fn ->
require Logger

Expand All @@ -228,7 +228,18 @@ defmodule TowerErrorTrackerTest do
end)
end)

assert [] = TestApp.Repo.all(ErrorTracker.Error) |> TestApp.Repo.preload(:occurrences)
expected_reason = "[emergency] Panic!"
expected_kind = "message #{:erlang.phash2(expected_reason)}"

assert_eventually(
[
%{
kind: ^expected_kind,
reason: ^expected_reason,
occurrences: [_]
}
] = TestApp.Repo.all(ErrorTracker.Error) |> TestApp.Repo.preload(:occurrences)
)
end

defp in_unlinked_process(fun) when is_function(fun, 0) do
Expand Down

0 comments on commit 4ee84d3

Please sign in to comment.