Skip to content

Commit b72e78a

Browse files
Update README with Sentry.LoggerHandler configuration (#856)
Co-authored-by: Andrea Leopardi <[email protected]>
1 parent 8ee657f commit b72e78a

File tree

1 file changed

+51
-10
lines changed

1 file changed

+51
-10
lines changed

README.md

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ defp deps do
2727
[
2828
# ...
2929

30-
{:sentry, "~> 10.0"},
31-
{:hackney, "~> 1.19"}
30+
{:sentry, "~> 10.8"},
31+
{:hackney, "~> 1.20"}
3232
]
3333
end
3434
```
@@ -40,7 +40,7 @@ end
4040
> defp deps do
4141
> [
4242
> # ...
43-
> {:sentry, "~> 10.0"},
43+
> {:sentry, "~> 10.8.1"},
4444
> {:jason, "~> 1.4"}
4545
> ]
4646
> end
@@ -61,17 +61,58 @@ config :sentry,
6161
6262
### Usage
6363

64-
This library comes with a [`:logger` handler][logger-handlers] to capture error messages coming from process crashes. To enable this, add the handler when your application starts:
64+
This library comes with a [`:logger` handler][logger-handlers] to capture error messages coming from process crashes. To enable this, add [`Sentry.LoggerHandler`](https://hexdocs.pm/sentry/Sentry.LoggerHandler.html) to your production configuration:
6565

66-
```diff
67-
def start(_type, _args) do
68-
+ :logger.add_handler(:sentry_handler, Sentry.LoggerHandler, %{})
66+
```elixir
67+
# config/prod.exs
68+
config :my_app, :logger, [
69+
{:handler, :my_sentry_handler, Sentry.LoggerHandler, %{
70+
config: %{
71+
metadata: [:file, :line],
72+
rate_limiting: [max_events: 10, interval: _1_second = 1_000],
73+
# Logs all messages with level `:error` and above to Sentry.
74+
# Remove :capture_log_messages and :level if you only want to report crashes.
75+
capture_log_messages: true,
76+
level: :error
77+
}
78+
}}
79+
]
6980

70-
# ...
71-
end
7281
```
7382

74-
The handler can also be configured to capture `Logger` metadata. See the documentation [here](https://hexdocs.pm/sentry/Sentry.LoggerBackend.html).
83+
And then add your logger when your application starts:
84+
85+
```elixir
86+
# lib/my_app/application.ex
87+
def start(_type, _args) do
88+
Logger.add_handlers(:my_app)
89+
90+
# ...
91+
end
92+
```
93+
94+
Alternatively, you can skip the `:logger` configuration and add the handler directly
95+
to your application's `start/2` callback:
96+
97+
```elixir
98+
# lib/my_app/application.ex
99+
def start(_type, _args) do
100+
:logger.add_handler(:my_sentry_handler, Sentry.LoggerHandler, %{
101+
config: %{
102+
metadata: [:file, :line],
103+
rate_limiting: [max_events: 10, interval: _1_second = 1_000],
104+
capture_log_messages: true,
105+
level: :error
106+
}
107+
})
108+
109+
# ...
110+
end
111+
```
112+
113+
See all logger configuration options [here](https://hexdocs.pm/sentry/Sentry.LoggerHandler.html).
114+
115+
#### Capture exceptions manually
75116

76117
Sometimes you want to capture specific exceptions manually. To do so, use [`Sentry.capture_exception/2`](https://hexdocs.pm/sentry/Sentry.html#capture_exception/2).
77118

0 commit comments

Comments
 (0)