elixir-error-tracker / error-tracker

🐛 An Elixir-based built-in error reporting and tracking solution
https://hex.pm/packages/error_tracker
Apache License 2.0
383 stars 17 forks source link

Notificate errors by email or Telegram #54

Closed ivanhercaz closed 2 months ago

ivanhercaz commented 2 months ago

Hi! First of all, just to say thank you all for this awesome and really great project that ease to track errors without building a heavy infrastructure and a lot of configuration. Congratulations! It works really nice just installing it and with the initial configuration steps you give in the documentation.

I am really interested in the notification of errors, because it can be really useful. I will implement it in a project handling the events emitted by ErrorTracker.Telemetry.

I just want to know if you are interested in having it implemented in ErrorTracker or if you prefer to keep it out by the moment:

  1. If you want it implemented in ErrorTracker, I can directly fork the project and start from there following your conventions, etc.
  2. If you want it outside of ErrorTracker, I will probably create a simple and easy package that implement this feature.

In case of 2, I would like to confirm if you agree with naming the package using error_tracker_ prefix.

In any case, 1 or 2, my idea and the roadmap in my head (I have not draw it yet!) is:

  1. Implement the handling of events.
  2. Let the user the possibility to send notifications by email.
  3. ... and then by Telegram.

I really prefer 3, because I use it more than the email, but I think it I will need to research and study more the implementation of that part.

Of course, any advice you can give is more than welcome! So I am going to wait for you answers ❤️, I am no in any hurry, so I can do it with calm in any of the cases.

Again, thank you very much for free and maintain this project!

Regards

odarriba commented 2 months ago

Hi!

Thanks for opening this issue to check it out with the team.

We think the project itself is not yet at a point in which adding notifications makes sense for us, as we think that if it is added to the core it should be extremely configurable, have several providers, allow to extend to custom ones, etc.

However, we want to thank you for your effort and we think that the best approach right now is your second option: implement it in a separate error_tracker_whatever package. If in the future it make sense to have it in the core package we can work on moving the functionality there :)

Also, please let us know once it is published for us to link it from the main package documentation and repository!

odarriba commented 2 months ago

I'm marking the issue as completed but feel free to comment on it to let us know when it's ready!

ivanhercaz commented 2 months ago

Hi @odarriba!

Thank you very much for your kindly answer ❤️

Completely understandable and reasonable!

If in the future it make sense to have it in the core package we can work on moving the functionality there :)

Also, please let us know once it is published for us to link it from the main package documentation and repository!

Of course! And who better to test it (and crash it!) than you. Once I have a minimum viable package to release it in Hex, I will notice you here.

See you (I hope sooner than later)!

grzuy commented 1 month ago

In any case, 1 or 2, my idea and the roadmap in my head (I have not draw it yet!) is:

1. Implement the handling of events.

2. Let the user the possibility to send notifications by email.

3. ... and then by Telegram.

Hi @ivanhercaz ,

If I understand correctly what your asking for, this is almost exactly what tower tries to solve. Handling of (error) events and passing them on to one or several reporters.

You can accomplish almost exactly what you want with tower_error_tracker, tower_email and writing a new tower_telegram (doesn't exist yet) and including those 3 as dependencies in your app, then config :tower, reporters: [TowerEmail, TowerErrorTracker, TowerTelegram].

Hope it helps.

ivanhercaz commented 1 month ago

Hi @ivanhercaz ,

If I understand correctly what your asking for, this is almost exactly what tower tries to solve. Handling of (error) events and passing them on to one or several reporters.

Hi @grzuy! I admit you that tower was a complete unknown project for me until now and it is really awesome.

You can accomplish almost exactly what you want with tower_error_tracker, tower_email and writing a new tower_telegram (doesn't exist yet) and including those 3 as dependencies in your app, then config :tower, reporters: [TowerEmail, TowerErrorTracker, TowerTelegram].

And even more awesome you have all of this reporters implemented, even having a specific for ErrorTracker, it is like to mix two awesome pieces in a wonderful puzzle!

I began with the idea of the Telegram reporter development for ErrorTracker, but I couldn't advance a lot, just visualize the idea and schematize it. So at this moment I tend toward the idea of create the Telegram reporter fortowerbecause it seems like 2x1,ErrorTrackercan benefit of it while even the reporter could be used without it, and in additiontower` also providers a reporter structure that can ease the development process.

Hope it helps.

It helps a lot. I am not going to have time to well test it, maybe just in local, but I will do it. And even if I get some free time I will try to do the Telegram reporter.

Thank you very much for sharing it!

We think the project itself is not yet at a point in which adding notifications makes sense for us, as we think that if it is added to the core it should be extremely configurable, have several providers, allow to extend to custom ones, etc.

@odarriba, given what you mentioned me previously about the notifications, given tower exists and there is already an existing integration with ErrorTracker, do you think it will have sense ErrorTracker itself provides the reporters?

jaimeiniesta commented 1 month ago

Hey everybody!

While I think that a plugin to get notifications by Telegram is great, I think that for 99% of users, email notifications can be enough, and that can be done with a simple GenServer like this:

defmodule MyApp.ErrorTracker.Notifier do
  use GenServer

  alias MyAppWeb.Emails.{ErrorTrackerNotifierEmail, SystemMailer}

  def start_link(_opts) do
    GenServer.start_link(__MODULE__, %{})
  end

  def init(state) do
    :ok =
      :telemetry.attach_many(
        "error-tracker-notifier",
        [
          [:error_tracker, :error, :new],
          [:error_tracker, :error, :unresolved]
        ],
        &handle_event/4,
        nil
      )

    {:ok, state}
  end

  def handle_event([:error_tracker, :error, event_type], _measurements, metadata, _config) do
    send_email(event_type, metadata)
  end

  defp send_email(event_type, metadata) do
    ErrorTrackerNotifierEmail.new_error(event_type, metadata) |> SystemMailer.deliver()
  end
end

And then starting it up in the application:

Supervisor.child_spec({MyApp.ErrorTracker.Notifier, name: :error_tracker_notifier}, id: :error_tracker_notifier),

The rest is just a standard mailer.

I'll be happy to send a PR to add this example to the documentation guides.

ivanhercaz commented 1 month ago

Hey everybody!

While I think that a plugin to get notifications by Telegram is great, I think that for 99% of users, email notifications can be enough

Hi @jaimeiniesta! Yes, I agree, telegram is just an example of possibility, and a niche haha.

crbelaus commented 1 month ago

I'll be happy to send a PR to add this example to the documentation guides.

Please do! That would be a great contribution @jaimeiniesta