MRdotB

MRdotB

DiscoLog - Use Discord as a logging service and error tracking solution

Hello,

I’m excited to introduce DiscoLog, a logging service and error tracking solution for Elixir that uses a Discord server as its backend.

Setup

DiscoLog is easy to set up with a mix task that creates three channels for you:

  • #occurrences: A forum-style channel where errors are grouped by fingerprint and tagged, making it easy to track and manage them.
  • #info: This channel pipes the output of Logger.info directly to Discord, keeping you informed of general application events.
  • #error: This channel pipes the output of Logger.error. If the logger content is not an exception, it goes here; otherwise, it’s routed to #occurrences.

Additionally, DiscoLog have integration with Plug, Phoenix, LiveView, and Oban to provide extra context through :telemetry

Additionally, DiscoLog includes a :logger handler that converts exceptions into error occurrences, even for processes that lack specific integrations, such as GenServer crashes.

By using Discord, DiscoLog benefits from built-in notifications through the Discord app. Another advantage of the forum channel is the ability to prevent specific errors from triggering notifications repeatedly.

The Story Behind DiscoLog

DiscoLog is built upon the foundations of error_tracker, for the :logger handler, I borrows a lot of code from sentry-elixir and appsignal-elixir

The idea for DiscoLog emerged while experimenting with Discord’s Bot API. I realized that the Discord Forum Channel type could serve as a good solution for error tracking. The primary challenge was Discord’s limited message size, but I overcame this by utilizing message attachments to handle larger payloads.

https://github.com/mrdotb/disco-log

First 10 of 16 Posts Switch mode

dimitarvp

dimitarvp

Wow that’s amazing, thanks for putting it together!

grzuy

grzuy

Hi @MRdotB ,

This is great, thanks for sharing!

I wonder how easy an integration with tower can be so to have a tower_discord package in order to be able to report errors both to Discord and other places at the same time.

MRdotB

MRdotB OP

I’m not sure what value integrating with Tower brings. DiscoLog already has a logger handler, so after configuring the Logger backend, doing Logger.error(some_exception) reports the error to the Discord backend. For telemetry, I also hook them and report separately. Adding DiscoLog to your app only requires modifying the config, with no additional code changes. Additionally, we have duplicate logic in event.ex, which I need for error tracking.

grzuy

grzuy

You’re right.
There’s too much overlap.

Makes more sense to have an hypothetical tower_discord be a separate package that only depends on tower and maybe a Discord elixir client.

Thanks :pray:

slouchpie

slouchpie

This is genius. Putting logs and error tracking into an app people are already using is such a smart idea. Well done!

MRdotB

MRdotB OP

I released disco_log v0.5.1:

  • it fixes an issue that was crashing the logger handler because some elixir type can’t be serialized as is

Meanwhile I have been using it in production on multiples side projects.
I’m very satisfied with the error tracking ! :slight_smile:

Next features on my list are:

  • Go to code the idea is to be able to click the occurrence and to go to the relevant github code on the specfic branch / tag
  • Active presence message to make the bot display some info about the node
martosaur

martosaur

I’ve only started using it but it’s been great so far. I like how setting up logging for multiple projects/environment is a matter of configuring category_id/channel_id.

I think I may have preferred starting DiscoLog under the application’s supervision tree and explicitly configuring logger handlers, but it might be too early to say :thinking:

MRdotB

MRdotB OP

Thanks for your PR! It’s been released on Hex as version 0.6.

I considered allowing DiscoLog to start under an application’s supervision tree and using explicit logger handlers, but decided against it to keep the setup simpler. Everything started by the DiscoLog application is configurable, though, so it still allows flexibility. You can check out the setup in DiscoLog’s application module.

martosaur

martosaur

I’ve been looking through the code recently, and I have a feeling that it’s feasible to allow users to start discolog under their supervision tree while maintaining the default option of running it as an independent application. Basically, it should boil down to only reading from global configuration on start up and then passing it to all downstream code (logger handler, Discord.Client, etc.) through composition. So, it’s possible for users to just set enable: false in global config and attach their own logger handlers with custom configuration.

The problem is that it’s a lot of changes and I can’t think of too many use cases that it would unlock. I suppose, if you want to publish to multiple guilds or categories, that will make it possible. I’d still be happy to do this, as I just love the idea behind DiscoLog and want it to be awesome, but I don’t want to create a 1000 LOC refactoring PR out of the blue without your blessing :sweat_smile: Do you think making DiscoLog highly configurable is worth it, or would you rather shelve the idea until some time in the future?

MRdotB

MRdotB OP

:wave:

Sure, it’s possible to achieve this without a big LOC I think.

The clean approach would be to include a Supervisor in the DiscoLog module. After that, you could run it in your application like this:

# lib/my_app/application.ex
def start(_type, _args) do
  children = [
    # other stuff,
    {DiscoLog, Application.fetch_env!(:my_app, :disco_log)}
  ]

  Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
end

In terms of configuration, there wouldn’t be much to change—just move the existing application logic in the supervisor. The current application would then call the supervisor instead.

For the logger handler, I think the current setup is fine. You can disable it and attach a custom handler yourself.

That said, I can’t think of specific use cases for this right now, but adding this feature would certainly make DiscoLog more flexible.

Oban is a great example of a library that give you a supervisor to start in your application.

Where Next?

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
387 14960 120
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
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

Other Trending Topics Top

type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
bjorng
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New

We're in Beta

About us Mission Statement