ErrorTrackerNotifier (error_tracker_notifier v0.2.0)

View Source

Attaches to ErrorTracker telemetry events and sends notifications for new errors.

Includes throttling to limit notification frequency for repeated errors.

Configuration

Configure in your config.exs:

# For email notifications
config :error_tracker_notifier,
  notification_type: :email,
  from_email: "support@example.com",
  to_email: "support@example.com",
  mailer: MyApp.Mailer,
  throttle_seconds: 10  # Optional: Throttle time between notifications (default: 10 seconds)

# For Discord webhook notifications
config :error_tracker_notifier,
  notification_type: :discord,
  webhook_url: "https://discord.com/api/webhooks/your-webhook-url",
  throttle_seconds: 30  # Optional: Throttle time between notifications

# For both email and Discord notifications
config :error_tracker_notifier,
  notification_type: [:email, :discord],  # Can be a single atom or a list
  from_email: "support@example.com",
  to_email: "support@example.com",
  mailer: MyApp.Mailer,
  webhook_url: "https://discord.com/api/webhooks/your-webhook-url",
  throttle_seconds: 60  # Optional: Throttle time between notifications

Setup

Add to your application.ex:

def start(_type, _args) do
  children = [
    # ...other children
    {ErrorTrackerNotifier, []}
  ]

  # Start the application supervisor
  Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
end

Summary

Functions

Returns a specification to start this module under a supervisor.

Send a notification for a new error occurrence.

Attach to ErrorTracker telemetry events. Automatically called when the GenServer starts.

Setup telemetry handlers directly without requiring the GenServer to be running. This can be used in applications where you want to handle telemetry events but don't want to start the GenServer process.

Starts the ErrorTrackerNotifier process.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_app_name()

get_config(key, default)

send_occurrence_notification(occurrence, header_txt)

Send a notification for a new error occurrence.

setup()

Attach to ErrorTracker telemetry events. Automatically called when the GenServer starts.

You can also call this function manually if you need to reattach telemetry events or if you're starting the process in a different way.

setup_telemetry()

Setup telemetry handlers directly without requiring the GenServer to be running. This can be used in applications where you want to handle telemetry events but don't want to start the GenServer process.

Returns :ok on success, or :error on failure.

start_link(opts \\ [])

Starts the ErrorTrackerNotifier process.

If the process is already started, returns {:error, {:already_started, pid}}. This is the expected behavior when started by a supervisor.