Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,11 @@ More information on why this may be necessary can be found here: https://github.

This library comes with an extension to capture all error messages that the Plug handler might not. This is based on [Logger.Backend](https://hexdocs.pm/logger/Logger.html#module-backends).

To set this up, add `{:ok, _} = Logger.add_backend(Sentry.LoggerBackend)` to your application's start function. Example:

```diff
# lib/my_app/application.ex
# ...
def start(_type, _opts) do
children = [
supervisor(MyApp.Repo, []),
supervisor(MyAppWeb.Endpoint, [])
]

opts = [strategy: :one_for_one, name: MyApp.Supervisor]

+ {:ok, _} = Logger.add_backend(Sentry.LoggerBackend)
# config/config.exs

Supervisor.start_link(children, opts)
end
+ config :logger,
+ backends: [:console, Sentry.LoggerBackend]
```

The backend can also be configured to capture Logger metadata, which is detailed [here](https://hexdocs.pm/sentry/Sentry.LoggerBackend.html).
Expand Down
20 changes: 5 additions & 15 deletions lib/sentry/logger_backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,16 @@ defmodule Sentry.LoggerBackend do
crashed processes. It replaces the previous `Sentry.Logger` sytem.

To include the backend in your application, the backend can be added in your
application file:
configuration file:

def start(_type, _opts) do
children = [
supervisor(MyApp.Repo, []),
supervisor(MyAppWeb.Endpoint, [])
]

opts = [strategy: :one_for_one, name: MyApp.Supervisor]

{:ok, _} = Logger.add_backend(Sentry.LoggerBackend)

Supervisor.start_link(children, opts)
end
config :logger,
backends: [:console, Sentry.LoggerBackend]

If you are on OTP 21+ and would like to configure the backend to include metadata from
`Logger.metadata/0` in reported events, it can be enabled:

{:ok, _} = Logger.add_backend(Sentry.LoggerBackend)
Logger.configure_backend(Sentry.LoggerBackend, include_logger_metadata: true)
config :logger, Sentry.LoggerBackend,
include_logger_metadata: true

It is important to be aware of whether this will include sensitive information
in Sentry events before enabling it.
Expand Down