Skip to content

Commit d2a3199

Browse files
Merge pull request #217 from getsentry/documentation-update
update Sentry.Logger docs
2 parents 2733e70 + 784de71 commit d2a3199

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/sentry/logger.ex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ defmodule Sentry.Logger do
1818
Supervisor.start_link(children, opts)
1919
end
2020
```
21+
22+
Your application will then be running a `Sentry.Logger` event handler that receives error report messages and send them to Sentry.
23+
24+
It is important to note that the same report handler can be added multiple times. If you run an umbrella app, and add the report handler in multiple individual applications, the same error will be reported multiple times (one for each handler). There are two solutions to fix it.
25+
26+
The first is to ensure that the handler is only added at the primary application entry-point. This will work, but can be brittle, and will not work for applications running the multiple release style.
27+
28+
The other solution is to check for existing handlers before trying to add another. Example:
29+
30+
```elixir
31+
if !(Sentry.Logger in :gen_event.which_handlers(:error_logger)) do
32+
:ok = :error_logger.add_report_handler(Sentry.Logger)
33+
end
34+
```
35+
36+
With this solution, if a `Sentry.Logger` handler is already running, it will not add another. One can add the code to each application, and there will only ever be one handler created. This solution is safer, but slightly more complex to manage.
2137
"""
2238

2339
use GenEvent

0 commit comments

Comments
 (0)