Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
crbelaus committed Sep 2, 2024
1 parent 420d9c2 commit 47a1b91
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 5 deletions.
11 changes: 9 additions & 2 deletions guides/Getting Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,19 @@ This is completely optional, and you can find more information about it in the `

## Notifications

We currently do not support notifications out of the box.
Currently ErrorTracker does not support notifications out of the box.

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

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

## Ignoring errors

ErrorTracker tracks every error by default. In certain cases some errors may be expected or just not interesting to track.
ErrorTracker provides functionality that allows you to ignore errors based on their attributes and context.

Take a look at the `ErrorTracker.Ignorer` behaviour for more information about how to implement your own ignorer.

## Pruning resolved errors

By default errors are kept in the database indefinitely. This is not ideal for production
Expand Down
8 changes: 5 additions & 3 deletions lib/error_tracker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ defmodule ErrorTracker do
{kind, reason} = normalize_exception(exception, stacktrace)
{:ok, stacktrace} = ErrorTracker.Stacktrace.new(stacktrace)
{:ok, error} = Error.new(kind, reason, stacktrace)

context = Map.merge(get_context(), given_context)

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

occurrence
if ignorer && !ignorer.ignore?(error, context) do
{_error, occurrence} = upsert_error!(error, stacktrace, context, reason)
occurrence
end
end

@doc """
Expand Down
39 changes: 39 additions & 0 deletions lib/error_tracker/ignorer.ex
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
21 changes: 21 additions & 0 deletions test/error_tracker/ignorer_test.exs
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

0 comments on commit 47a1b91

Please sign in to comment.