Skip to content

Commit 47a1b91

Browse files
committed
Update docs
1 parent 420d9c2 commit 47a1b91

File tree

4 files changed

+74
-5
lines changed

4 files changed

+74
-5
lines changed

guides/Getting Started.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,19 @@ This is completely optional, and you can find more information about it in the `
133133

134134
## Notifications
135135

136-
We currently do not support notifications out of the box.
136+
Currently ErrorTracker does not support notifications out of the box.
137137

138-
However, we provideo some detailed Telemetry events that you may use to implement your own notifications following your custom rules and notification channels.
138+
However, it provides some detailed Telemetry events that you may use to implement your own notifications following your custom rules and notification channels.
139139

140140
If you want to take a look at the events you can attach to, take a look at `ErrorTracker.Telemetry` module documentation.
141141

142+
## Ignoring errors
143+
144+
ErrorTracker tracks every error by default. In certain cases some errors may be expected or just not interesting to track.
145+
ErrorTracker provides functionality that allows you to ignore errors based on their attributes and context.
146+
147+
Take a look at the `ErrorTracker.Ignorer` behaviour for more information about how to implement your own ignorer.
148+
142149
## Pruning resolved errors
143150

144151
By default errors are kept in the database indefinitely. This is not ideal for production

lib/error_tracker.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ defmodule ErrorTracker do
107107
{kind, reason} = normalize_exception(exception, stacktrace)
108108
{:ok, stacktrace} = ErrorTracker.Stacktrace.new(stacktrace)
109109
{:ok, error} = Error.new(kind, reason, stacktrace)
110-
111110
context = Map.merge(get_context(), given_context)
112111

113-
{_error, occurrence} = upsert_error!(error, stacktrace, context, reason)
112+
ignorer = Application.get_env(:error_tracker, :ignorer)
114113

115-
occurrence
114+
if ignorer && !ignorer.ignore?(error, context) do
115+
{_error, occurrence} = upsert_error!(error, stacktrace, context, reason)
116+
occurrence
117+
end
116118
end
117119

118120
@doc """

lib/error_tracker/ignorer.ex

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
defmodule ErrorTracker.Ignorer do
2+
@moduledoc """
3+
Behaviour for ignoring errors.
4+
5+
The ErrorTracker tracks every error that happens in your application. In certain cases you may
6+
want to ignore some errors and don't track them. To do so you can implement this behaviour.
7+
8+
defmodule MyApp.ErrorIgnorer do
9+
@behaviour ErrorTracker.Ignorer
10+
11+
@impl true
12+
def ignore?(error = %ErrorTracker.Error{}, context) do
13+
# return true if the error should be ignored
14+
end
15+
end
16+
17+
Once implemented, include it in the ErrorTracker configuration:
18+
19+
config :error_tracker, ignorer: MyApp.ErrorIgnorer
20+
21+
With this configuration in place, the ErrorTracker will call `MyApp.ErrorIgnorer.ignore?/2` before
22+
tracking errors. If the function returns `true` the error will be ignored and won't be tracked.
23+
24+
> #### A note on performance {: .warning}
25+
>
26+
> Keep in mind that the `ignore?/2` will be called in the context of the ErrorTracker itself.
27+
> Slow code will have a significant impact in the ErrorTracker performance. Buggy code can bring
28+
> the ErrorTracker process down.
29+
"""
30+
31+
@doc """
32+
Decide wether the given error should be ignored or not.
33+
34+
This function receives both the current Error and context and should return a boolean indicating
35+
if it should be ignored or not. If the function returns true the error will be ignored, otherwise
36+
it will be tracked.
37+
"""
38+
@callback ignore?(error :: ErrorTracker.Error.t(), context :: map()) :: boolean
39+
end

test/error_tracker/ignorer_test.exs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
defmodule ErrorTracker.IgnorerTest do
2+
use ErrorTracker.Test.Case
3+
4+
setup_all do
5+
Application.put_env(:error_tracker, :ignorer, ErrorTracker.EveryErrorIgnorer)
6+
end
7+
8+
test "ignores errors" do
9+
refute report_error(fn -> raise "[IGNORE] Sample error" end)
10+
assert report_error(fn -> raise "Sample error" end)
11+
end
12+
end
13+
14+
defmodule ErrorTracker.EveryErrorIgnorer do
15+
@behaviour ErrorTracker.Ignorer
16+
17+
@impl true
18+
def ignore?(error, _context) do
19+
String.contains?(error.reason, "[IGNORE]")
20+
end
21+
end

0 commit comments

Comments
 (0)