grzuy

grzuy

Tower - Agnostic Error Tracking in Elixir

:castle: Tower is an Elixir library that provides a common interface for Error Tracking and Reporting, agnostic 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!

Most Liked

grzuy

grzuy

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

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.18.2).

Where Next?

Popular in Libraries Top

pkrawat1
Presenting Aviacommerce, open source e-commerce platform in Elixir Aviacommerce is an open source e-commerce platform in Elixir. We at...
New
mindok
What is ContEx? A pure Elixir server-side data plotting/charting library outputting SVG. It has nice barcharts in particular and works g...
New
achempion
Hi, I would like to tell about my initiative to further maintain and develop Waffle project which is the fork of Arc library. The progre...
New
New
blatyo
https://www.conduitframework.com/ The best overview for how things are tied together is this presentation. Modules and functions are pre...
New
aditya7iyengar
Rummage.Ecto and Rummage.Phoenix provide ways to perform Searching, Sorting and Pagination over Ecto queries and Phoenix collections. Fo...
New
Crowdhailer
I have been updating a library that allows you to pipe between functions that use the erlang result tuple convention. Assuming you have...
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
bryanjos
Hi, I just published version 0.23.0 of Elixirscript. Most of the changes are around JavaScript interop now that Elixirscript uses the ...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Sub Categories:

We're in Beta

About us Mission Statement