Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: usage #43

Merged
merged 1 commit into from
Aug 20, 2024
Merged
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
74 changes: 71 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,88 @@
[![Hex.pm](https://img.shields.io/hexpm/v/tower.svg)](https://hex.pm/packages/tower)
[![Docs](https://img.shields.io/badge/docs-gray.svg)](https://hexdocs.pm/tower)

Solid error handling and reporting
Solid and simple **error handling** and **reporting** in Elixir

## Installation
## Usage

The package can be installed by adding `tower` to your list of dependencies in `mix.exs`:
Tower is an Elixir package that tries to do one job well, **handle** error **events** in an Elixir application
**and inform** about them to configured **reporters** (one or many).

You can either write your own reporter or use any amount of the following reporters:

- [tower_rollbar](http://github.com/mimiquate/tower_rollbar)
- [tower_slack](http://github.com/mimiquate/tower_slack)

In case you use any of the above reporters, you don't need to include `tower` as a dependency. It will be a transitive dependency
of any of the above reporters.

### Writing a custom reporter

In case you don't want to use pre-built reporters and you want to write your own, first include
the core `tower` package:

```elixir
# mix.exs
def deps do
[
{:tower, "~> 0.4.0"}
]
end
```

Implement you custom reporting by implementing `Tower.Reporter` behaviour:

```elixir
# lib/my_app/error_reporter.ex
defmodule MyApp.ErrorReporter do
use Tower.Reporter

@impl true
def report_event(%Tower.Event{} = event) do
# Do whatever you want with event...

# A `Tower.Event` is a struct with the following typespec:
#
# %Tower.Event{
# id: Uniq.UUID.t(),
# datetime: DateTime.t(),
# level: :logger.level(),
# kind: :error | :exit | :throw | :message,
# reason: Exception.t() | term(),
# stacktrace: Exception.stacktrace() | nil,
# log_event: :logger.log_event() | nil,
# plug_conn: struct() | nil,
# metadata: map()
# }
end
end
```

Tell `tower` you want your reporter to be informed about events.

```elixir
# config/runtime.exs

config :tower, reporters: [MyApp.ErrorReporter]
```

Finally attach Tower to your application.

```elixir
# lib/my_app/application.ex
defmodule MyApp.Application do
...

def start(_type, _args) do
Tower.attach()

...
end

...
end
```

## License

Copyright 2024 Mimiquate
Expand Down
Loading