Skip to content

Commit f66ee52

Browse files
Update README.md
1 parent cb04518 commit f66ee52

File tree

1 file changed

+40
-63
lines changed

1 file changed

+40
-63
lines changed

README.md

Lines changed: 40 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@ end
3333

3434
In your Plug.Router or Phoenix.Router, add the following lines:
3535

36-
```elixir
37-
use Plug.ErrorHandler
38-
use Sentry.Plug
36+
```diff
37+
# lib/my_app_web/router.ex
38+
defmodule MyAppWeb.Router do
39+
use MyAppWeb, :router
40+
+ use Plug.ErrorHandler
41+
+ use Sentry.Plug
3942
```
4043

4144
If you are using Phoenix, you can also include [Sentry.Phoenix.Endpoint](https://hexdocs.pm/sentry/Sentry.Phoenix.Endpoint.html) in your Endpoint. This module captures errors occurring in the Phoenix pipeline before the request reaches the Router:
4245

43-
```elixir
44-
use Phoenix.Endpoint, otp_app: :my_app
45-
use Sentry.Phoenix.Endpoint
46+
```diff
47+
use Phoenix.Endpoint, otp_app: :my_app
48+
+use Sentry.Phoenix.Endpoint
4649
```
4750

4851
More information on why this may be necessary can be found here: https://github.com/getsentry/sentry-elixir/issues/229 and https://github.com/phoenixframework/phoenix/issues/2791
@@ -53,19 +56,21 @@ This library comes with an extension to capture all error messages that the Plug
5356

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

56-
```elixir
57-
def start(_type, _opts) do
58-
children = [
59-
supervisor(MyApp.Repo, []),
60-
supervisor(MyAppWeb.Endpoint, [])
61-
]
59+
```diff
60+
# lib/my_app/application.ex
61+
# ...
62+
def start(_type, _opts) do
63+
children = [
64+
supervisor(MyApp.Repo, []),
65+
supervisor(MyAppWeb.Endpoint, [])
66+
]
6267

63-
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
68+
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
6469

65-
{:ok, _} = Logger.add_backend(Sentry.LoggerBackend)
70+
+ {:ok, _} = Logger.add_backend(Sentry.LoggerBackend)
6671

67-
Supervisor.start_link(children, opts)
68-
end
72+
Supervisor.start_link(children, opts)
73+
end
6974
```
7075

7176
The backend can also be configured to capture Logger metadata, which is detailed [here](https://hexdocs.pm/sentry/Sentry.LoggerBackend.html).
@@ -96,6 +101,25 @@ For optional settings check the [docs](https://hexdocs.pm/sentry/readme.html).
96101

97102
## Configuration
98103

104+
Sentry has a range of configuration options, but most applications will have a configuration that looks like the following:
105+
106+
```elixir
107+
# config/config.exs
108+
config :sentry,
109+
dsn: "https://[email protected]/1",
110+
environment_name: Mix.env(),
111+
included_environments: [:prod],
112+
enable_source_code_context: true,
113+
root_source_code_path: File.cwd!()
114+
```
115+
116+
The `environment_name` and `included_environments` work together to determine
117+
if and when Sentry should send events to the server. If the currently configured
118+
`:environment_name` is in the configured list of `:included_environments`, the
119+
event will be sent.
120+
121+
The full range of options is the following:
122+
99123
| Key | Required | Default | Notes |
100124
| ------------- | -----------------|--------------|-------|
101125
| `dsn` | True | n/a | |
@@ -122,53 +146,6 @@ For optional settings check the [docs](https://hexdocs.pm/sentry/readme.html).
122146
| `json_library` | False | `Jason` | |
123147
| `log_level` | False | `:warn` | This sets the log level used when Sentry fails to send an event due to an invalid event or API error |
124148

125-
An example production config might look like this:
126-
127-
```elixir
128-
config :sentry,
129-
dsn: "https://[email protected]/1",
130-
environment_name: :prod,
131-
included_environments: [:prod],
132-
enable_source_code_context: true,
133-
root_source_code_path: File.cwd!(),
134-
tags: %{
135-
env: "production"
136-
},
137-
hackney_opts: [pool: :my_pool],
138-
in_app_module_whitelist: [MyApp]
139-
```
140-
141-
The `environment_name` and `included_environments` work together to determine
142-
if and when Sentry should record exceptions. The `environment_name` is the
143-
name of the current environment. In the example above, we have explicitly set
144-
the environment to `:prod` which works well if you are inside an environment
145-
specific configuration like `config/prod.exs`.
146-
147-
Alternatively, you could use Mix.env in your general configuration file:
148-
149-
```elixir
150-
config :sentry, dsn: "https://[email protected]/1",
151-
included_environments: [:prod],
152-
environment_name: Mix.env
153-
```
154-
155-
You can even rely on more custom determinations of the environment name. It's
156-
not uncommon for most applications to have a "staging" environment. In order
157-
to handle this without adding an additional Mix environment, you can set an
158-
environment variable that determines the release level.
159-
160-
```elixir
161-
config :sentry, dsn: "https://[email protected]/1",
162-
included_environments: ~w(production staging),
163-
environment_name: System.get_env("RELEASE_LEVEL") || "development"
164-
```
165-
166-
In this example, we are getting the environment name from the `RELEASE_LEVEL`
167-
environment variable. If that variable does not exist, we default to `"development"`.
168-
Now, on our servers, we can set the environment variable appropriately. On
169-
our local development machines, exceptions will never be sent, because the
170-
default value is not in the list of `included_environments`.
171-
172149
Sentry uses the [hackney HTTP client](https://github.com/benoitc/hackney) for HTTP requests. Sentry starts its own hackney pool named `:sentry_pool` with a default connection pool of 50, and a connection timeout of 5000 milliseconds. The pool can be configured with the `hackney_pool_max_connections` and `hackney_pool_timeout` configuration keys. If you need to set other [hackney configurations](https://github.com/benoitc/hackney/blob/master/doc/hackney.md#request5) for things like a proxy, using your own pool or response timeouts, the `hackney_opts` configuration is passed directly to hackney for each request.
173150

174151
### Context and Breadcrumbs

0 commit comments

Comments
 (0)