Commit b563d7a
authored
Fix error grouping issue (#133)
The errors are being grouped in a wrong way because a type mismatch
comparison was done between the application name and the stacktrace
application name.
The fix is to convert the configured application name to a string and be
able to compare it with the stacktrace application name.
You can test it putting this script on the root project:
<details>
```elixir
Mix.install([
{:ecto_sql, "~> 3.0"},
{:postgrex, "~> 0.1"},
{:error_tracker, path: "."},
{:bandit, "~> 1.0"}
])
### ErrorLogger config
Application.put_env(:error_tracker, :repo, Repo)
Application.put_env(:error_tracker, :otp_app, :myapp)
Application.put_env(:error_tracker, :enabled, true)
defmodule AddErrorTracker do
use Ecto.Migration
def up, do: ErrorTracker.Migration.up(version: 4)
def down, do: ErrorTracker.Migration.down(version: 1)
end
### Common config
Application.put_env(:myapp, Repo, database: "mix_install_examples")
defmodule Repo do
use Ecto.Repo, adapter: Ecto.Adapters.Postgres, otp_app: :myapp
end
defmodule Migration0 do
use Ecto.Migration
def change do
create table("posts") do
add(:title, :string)
timestamps(type: :utc_datetime_usec)
end
end
end
defmodule Post do
use Ecto.Schema
schema "posts" do
field(:title, :string)
timestamps(type: :utc_datetime_usec)
end
end
defmodule Main do
import Ecto.Query, warn: false
def migrate do
Repo.__adapter__().storage_down(Repo.config())
:ok = Repo.__adapter__().storage_up(Repo.config())
{:ok, _} = Repo.start_link([])
Ecto.Migrator.run(Repo, [{0, Migration0}, {1, AddErrorTracker}], :up, all: true, log_migrations_sql: :info)
end
def register_app_and_modules do
:application.load({:application, :myapp, [
{:description, ~c"My sample application"},
{:vsn, ~c"0.1.0"},
{:modules, [Router]},
{:registered, [Router]},
{:applications, [:kernel, :stdlib]}
]})
end
def run_http_server do
Supervisor.start_link([{Bandit, [plug: Router, port: 1234]}], strategy: :one_for_one)
end
def make_requests do
:inets.start()
:httpc.request("http://localhost:1234/route1")
:httpc.request("http://localhost:1234/route2")
end
def check_what_was_collected do
ErrorTracker.Error
|> Repo.all()
|> IO.inspect()
ErrorTracker.Occurrence
|> Repo.all()
|> Enum.map(&Enum.take(&1.stacktrace.lines, 2))
|> IO.inspect()
end
end
defmodule Router do
use Plug.Router
use ErrorTracker.Integrations.Plug
plug(:match)
plug(:dispatch)
get "/route1" do
Repo.get!(Post, 1)
send_resp(conn, 200, "Anything")
end
get "/route2" do
Repo.get!(Post, 2)
send_resp(conn, 200, "Anything")
end
end
Main.migrate()
Main.register_app_and_modules()
Main.run_http_server()
Main.make_requests()
Main.check_what_was_collected() # <- demonstrates the issue
Process.sleep(:infinity)
```
</details>
This closes #1321 parent 4763e55 commit b563d7a
File tree
2 files changed
+16
-6
lines changed- lib/error_tracker/schemas
- test
2 files changed
+16
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| |||
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
32 | | - | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
40 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
41 | 48 | | |
42 | | - | |
43 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
44 | 54 | | |
45 | 55 | | |
46 | 56 | | |
| |||
0 commit comments