-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule ErrorTracker.Ignorer do | ||
@moduledoc """ | ||
Behaviour for ignoring errors. | ||
The ErrorTracker tracks every error that happens in your application. In certain cases you may | ||
want to ignore some errors and don't track them. To do so you can implement this behaviour. | ||
defmodule MyApp.ErrorIgnorer do | ||
@behaviour ErrorTracker.Ignorer | ||
@impl true | ||
def ignore?(error = %ErrorTracker.Error{}, context) do | ||
# return true if the error should be ignored | ||
end | ||
end | ||
Once implemented, include it in the ErrorTracker configuration: | ||
config :error_tracker, ignorer: MyApp.ErrorIgnorer | ||
With this configuration in place, the ErrorTracker will call `MyApp.ErrorIgnorer.ignore?/2` before | ||
tracking errors. If the function returns `true` the error will be ignored and won't be tracked. | ||
> #### A note on performance {: .warning} | ||
> | ||
> Keep in mind that the `ignore?/2` will be called in the context of the ErrorTracker itself. | ||
> Slow code will have a significant impact in the ErrorTracker performance. Buggy code can bring | ||
> the ErrorTracker process down. | ||
""" | ||
|
||
@doc """ | ||
Decide wether the given error should be ignored or not. | ||
This function receives both the current Error and context and should return a boolean indicating | ||
if it should be ignored or not. If the function returns true the error will be ignored, otherwise | ||
it will be tracked. | ||
""" | ||
@callback ignore?(error :: ErrorTracker.Error.t(), context :: map()) :: boolean | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule ErrorTracker.IgnorerTest do | ||
use ErrorTracker.Test.Case | ||
|
||
setup_all do | ||
Application.put_env(:error_tracker, :ignorer, ErrorTracker.EveryErrorIgnorer) | ||
end | ||
|
||
test "ignores errors" do | ||
refute report_error(fn -> raise "[IGNORE] Sample error" end) | ||
assert report_error(fn -> raise "Sample error" end) | ||
end | ||
end | ||
|
||
defmodule ErrorTracker.EveryErrorIgnorer do | ||
@behaviour ErrorTracker.Ignorer | ||
|
||
@impl true | ||
def ignore?(error, _context) do | ||
String.contains?(error.reason, "[IGNORE]") | ||
end | ||
end |