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

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
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

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews