Phx2Ban.Telemetry (Phx2Ban v0.2.2)

This module contains helper functions so that you can interact with the telemetry events that this library emits. All of the *_event() functions define the signatures for the telemetry events and hooking into the telemetry events should be done via these functions as opposed to using the underlying event signature in case the signature changes in the future. For example, if you want to hook into the event the is emitted when a malicious IP address is unblocked, you could do the following:

:telemetry.attach(
  "my_app_phx_2_ban_logger",
  Telemetry.malicious_ip_unblocked_event(),
  fn _event, _measurements, %{remote_ip: remote_ip}, _config->
    Logger.info("Phx2Ban has unblocked the following IP address: #{remote_ip}")
  end,
  nil
)

Be sure to check out the documentation for each *_event function to see what measurements and metadata are provided via telemetry.

Summary

Functions

If you need to debug what is going on inside of Phx2Ban, you can attach the provided logger and see all of the events occurring within Phx2Ban. It is no recommended that this remain enabled as you may be generating a lot of noise in your logs.

Detach the debugging logger so that log messages are no longer produced.

This event is emitted when a remote IP address has made enough malicious requests that it is now blocked.

This event is emitted when a remote IP address has been removed from the blocklist.

This event is emitted when a request is made and it is determined that the request is malicious.

This event is emitted when a request from a blocked IP is rejected by the Phx2Ban.Plug module.

This event is emitted when a valid request passes through the Phx2Ban.Plug module.

Functions

Link to this function

attach_logger(opts \\ [])

If you need to debug what is going on inside of Phx2Ban, you can attach the provided logger and see all of the events occurring within Phx2Ban. It is no recommended that this remain enabled as you may be generating a lot of noise in your logs.

Link to this function

detach_logger()

Detach the debugging logger so that log messages are no longer produced.

Link to this function

malicious_ip_blocked_event()

This event is emitted when a remote IP address has made enough malicious requests that it is now blocked.

Measurements:

  • :system_time - Then time when the event occurred.

Metadata:

  • :remote_ip - The IP address of the request.
Link to this function

malicious_ip_unblocked_event()

This event is emitted when a remote IP address has been removed from the blocklist.

Measurements:

  • :system_time - Then time when the event occurred.

Metadata:

  • :remote_ip - The IP address of the request.
Link to this function

malicious_request_event()

This event is emitted when a request is made and it is determined that the request is malicious.

Measurements:

  • :system_time - Then time when the event occurred.

Metadata:

  • :remote_ip - The IP address of the request.
Link to this function

rejected_request_event()

This event is emitted when a request from a blocked IP is rejected by the Phx2Ban.Plug module.

Measurements:

  • :system_time - Then time when the event occurred.

Metadata:

  • :request_path - The path that was requested.
  • :remote_ip - The IP address of the request.
Link to this function

valid_request_event()

This event is emitted when a valid request passes through the Phx2Ban.Plug module.

Measurements:

  • :system_time - Then time when the event occurred.

Metadata:

  • :request_path - The path that was requested.
  • :remote_ip - The IP address of the request.