|
1 | | -# sentry |
| 1 | +# Sentry |
2 | 2 |
|
3 | 3 |  |
4 | 4 | [](https://hex.pm/packages/sentry) |
5 | 5 | [](https://hexdocs.pm/sentry) |
6 | 6 |
|
7 | | -The official Sentry client for Elixir which provides a simple API to capture exceptions, automatically handle Plug exceptions, and provides a backend for the Elixir Logger. This documentation represents unreleased features, for documentation on the current release, see [here](https://hexdocs.pm/sentry/readme.html). |
| 7 | +The official Sentry client for Elixir which provides a simple API to capture exceptions, automatically handle Plug exceptions, and provides a backend for the Elixir Logger. |
| 8 | + |
| 9 | +💁: This README documents unreleased features (from the `master` branch). For documentation on the current release, see [the official documentation][docs]. |
8 | 10 |
|
9 | 11 | ## Installation |
10 | 12 |
|
11 | | -To use Sentry with your projects, edit your mix.exs file and add it as a dependency. Sentry does not install a JSON library nor HTTP client by itself. Sentry will default to trying to use Jason for JSON operations and Hackney for HTTP requests, but can be configured to use other ones. To use the default ones, do: |
| 13 | +To use Sentry in your project, add it as a dependency in your `mix.exs` file. Sentry does not install a JSON library nor HTTP client by itself. Sentry will default to trying to use [Jason] for JSON serialization and [Hackney] for HTTP requests, but can be configured to use other ones. To use the default ones, do: |
12 | 14 |
|
13 | 15 | ```elixir |
14 | 16 | defp deps do |
15 | 17 | [ |
16 | 18 | # ... |
| 19 | + |
17 | 20 | {:sentry, "8.0.0"}, |
18 | | - {:jason, "~> 1.1"}, |
19 | | - {:hackney, "~> 1.8"}, |
20 | | - # if you are using plug_cowboy |
21 | | - {:plug_cowboy, "~> 2.3"}, |
| 21 | + {:jason, "~> 1.4"}, |
| 22 | + {:hackney, "~> 1.19"} |
22 | 23 | ] |
23 | 24 | end |
24 | 25 | ``` |
25 | 26 |
|
| 27 | +## Usage |
| 28 | + |
| 29 | +This is a short overview of how to use the library. For complete documentation, refer to [HexDocs][docs]. |
| 30 | + |
26 | 31 | ### Capture Crashed Process Exceptions |
27 | 32 |
|
28 | | -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). You can add it as a backend when your application starts: |
| 33 | +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: |
29 | 34 |
|
30 | 35 | ```diff |
31 | | -# lib/my_app/application.ex |
| 36 | + def start(_type, _args) do |
| 37 | ++ :logger.add_handler(:sentry_handler, Sentry.LoggerHandler, %{}) |
32 | 38 |
|
33 | | -+ def start(_type, _args) do |
34 | | -+ Logger.add_backend(Sentry.LoggerBackend) |
| 39 | + # ... |
| 40 | + end |
35 | 41 | ``` |
36 | 42 |
|
37 | | -The backend can also be configured to capture Logger metadata, which is detailed [here](https://hexdocs.pm/sentry/Sentry.LoggerBackend.html). |
| 43 | +The handler can also be configured to capture `Logger` metadata. See the documentation [here](https://hexdocs.pm/sentry/Sentry.LoggerBackend.html). |
38 | 44 |
|
39 | 45 | ### Capture Arbitrary Exceptions |
40 | 46 |
|
41 | | -Sometimes you want to capture specific exceptions. To do so, use `Sentry.capture_exception/2`. |
| 47 | +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). |
42 | 48 |
|
43 | 49 | ```elixir |
44 | 50 | try do |
45 | 51 | ThisWillError.really() |
46 | 52 | rescue |
47 | 53 | my_exception -> |
48 | | - Sentry.capture_exception(my_exception, [stacktrace: __STACKTRACE__, extra: %{extra: information}]) |
| 54 | + Sentry.capture_exception(my_exception, stacktrace: __STACKTRACE__) |
49 | 55 | end |
50 | 56 | ``` |
51 | 57 |
|
52 | 58 | ### Capture Non-Exception Events |
53 | 59 |
|
54 | | -Sometimes you want to capture messages that are not Exceptions. |
| 60 | +Sometimes you want to capture **messages** that are not exceptions. To do that, use [`Sentry.capture_message/2`](https://hexdocs.pm/sentry/Sentry.html#capture_exception/2): |
55 | 61 |
|
56 | 62 | ```elixir |
57 | | - Sentry.capture_message("custom_event_name", extra: %{extra: information}) |
| 63 | +Sentry.capture_message("custom_event_name", extra: %{extra: information}) |
58 | 64 | ``` |
59 | 65 |
|
60 | | -For optional settings check the [docs](https://hexdocs.pm/sentry/readme.html). |
| 66 | +For optional settings check the [documentation][docs]. |
61 | 67 |
|
62 | 68 | ## Configuration |
63 | 69 |
|
@@ -189,3 +195,8 @@ When testing, you will also want to set the `send_result` type to `:sync`, so th |
189 | 195 | ## License |
190 | 196 |
|
191 | 197 | This project is Licensed under the [MIT License](https://github.com/getsentry/sentry-elixir/blob/master/LICENSE). |
| 198 | + |
| 199 | +[Jason]: https://github.com/michalmuskala/jason |
| 200 | +[Hackney]: https://github.com/benoitc/hackney |
| 201 | +[docs]: https://hexdocs.pm/sentry/readme.html |
| 202 | +[logger-handlers]: https://www.erlang.org/doc/apps/kernel/logger_chapter#handlers |
0 commit comments