grzuy

grzuy

:castle: Tower is an Elixir library that provides a standard interface for Exception Tracking and Reporting, agnostic/neutral to which services or destinations you prefer to report to.

  • Automatically listens for and reports un-handled exceptions occurring in any process.
  • Provides small set of public functions for you to manually report any handled exception (Tower.report_exception and Tower.report_message, among a few more)
  • Reports to one or many of your preferred services or destinations (separate package reporters/adapters) you configured with config :tower, reporters: [...].

Reporters/adapters currently supported:

Why?

  • De-coupling of error capturing from error reporting.
  • Be able to easily report to more than one place, either temporarily in case of transitioning from services, or for back-up reasons.
  • Easier to switch or try out new services or destinations
  • Having capturing logic implemented once may make it easier to respond to future changes in BEAM and Elixir, that benefit multiple reporter packages.

More at mimiquate/tower#Motivation.

Example Scenarios

Scenario #1

You want to report to Sentry.

  • You include tower_sentry .
  • Set a few Sentry-specific config setting.
  • Set config :tower, reporters: [TowerSentry]

Automatic reporting of exceptions will “just work”.

Manually report by calling Tower.report_exception anywhere you like in your application code, like so:

  try do
    # possibly raising code
  rescue
    exception ->
      Tower.report_exception(exception, __STACKTRACE__)
  end

Scenario #2

You need/want to switch service from Sentry to Honeybadger.

  • Replace tower_sentry with tower_honeybadger in your dependencies.
  • Replace config :tower, reporters: [TowerSentry] with config :tower, reporters: [TowerHoneybadger]
  • Remove Sentry-specific configs.
  • Add Honeybadger-specific config, like setting API Key.
  • Automatic reporting of exceptions continue to “just work” without any changes.
  • Manual report calls to Tower.report_exception throughout your application code unchanged.

Scenario #3

You are reporting to Sentry and you want to test ErrorTracker while continuing to report to Sentry.

  • Add tower_error_tracker.
  • Follow a few ErrorTracker specific configs.
  • Update config :tower, reporters: [TowerSentry] to config :tower, reporters: [TowerSentry, TowerErrorTracker] .
  • Automatic reporting of exceptions continue to “just work” without any changes.
  • Manual report calls to Tower.report_exception throughout your application code unchanged.
  • Now you will have exceptions reported to both Sentry and ErrorTracker.

The Ephemeral Reporter

You can include the built-in Tower.EphemeralReporter in the reporters: config list. It will keep the last 50 heard exceptions stored in naive Agent state. Useful for testing, development, and occasional production debugging.

iex(1)> Tower.EphemeralReporter.events()
[]
iex(2)> Task.start(fn -> raise "exception within an async task" end)
{:ok, #PID<0.344.0>}

11:52:12.684 [error] Task #PID<0.344.0> started from #PID<0.343.0> terminating
** (RuntimeError) exception within an async task
    (elixir 1.17.3) src/elixir.erl:386: :elixir.eval_external_handler/3
Function: #Function<43.39164016/0 in :erl_eval.expr/6>
    Args: []
iex(3)> Tower.EphemeralReporter.events()
[
  %Tower.Event{
    id: "019290aa-4c2a-7853-85f9-e9171e16ef04",
    similarity_id: 9949489,
    datetime: ~U[2024-10-15 14:52:12.684704Z],
    level: :error,
    kind: :error,
    reason: %RuntimeError{message: "exception within an async task"},
    ...
  }
]

Support for more services?

We may write reporters for new services.

But we strongly encourage others to help and write and publish new reporters/adapters as you see fit and value.

Links

What’s next?

We plan to continue polishing, maturing and improving it. But we also need the community :slightly_smiling_face:

Any feedback is in any form very much appreciated!
Please comment, use it, find and report bugs.
Ideas or feature requests are encouraged in the GitHub repo Discussions.

Thank you for taking the time to read!

https://github.com/mimiquate/tower

Showing Posts 1 to 3

grzuy

grzuy OP

For what is worth, sharing a related recent blog post that goes into a little more detail Tower: Universal and Agnostic Elixir Exception Tracker.

KristerV

KristerV

i tried switching from ErrorTracker to Tower (plus tower_error_tracker) to collect Logger.error() logs. buuuut it seems that that’s not actually supported? I saw the LoggerHandler module and assumed that’s what it’s for.

i can get so far that exeptions are caught, but not Logger logs. what’s the procedure there?

edit: @JonRowe figured it out. the conf has to have this value:

config :tower, log_level: :error

otherwise the LoggerHandler gets attached, but all messages are filtered out. doesn’t look like there’s anything in the docs about this, will raise an issue.

grzuy

grzuy OP

Indeed, was not well documented.
Hopefully it is now: docs: clarifies configuration options by grzuy · Pull Request #128 · mimiquate/tower · GitHub.

Thank you.

Note that LoggerHandler does listen for BOTH “logger messages” and “unhandled exceptions/crashes”.

Unhandled exception/crashes should actually land in the LoggerHandler as just “logger messages” with the special metadata key “crash_reason” (see :crash_reason listed in Logger — Logger v1.20.2).

— All posts loaded —

Where Next? Top

Trending in Announcing Top

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 11030 135
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New

Other Trending Topics Top

mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews