Rexsilient.Notifier.TelemetryNotifier (Rexsilient v1.0.0)

Copy Markdown View Source

The default notifier: emits every notification as a :telemetry event.

The event name is [:rexsilient, kind, moment], following the :telemetry.span/3 conventions: :before is emitted as :start and :after as :stop. The retry :stop moment is emitted as :give_up, so it does not clash with the :stop event of each attempt.

The numeric keys of the notification's state, :monotonic_time, :system_time, :duration, :delay and :timeout, are the measurements; every other key is metadata. A :timeout of :infinity stays in the metadata. See Rexsilient.Notifier for what each moment means.

Events

[:rexsilient, :circuit_breaker, event]:

EventMeasurementsMetadata
:startmonotonic_time, system_timename
:stopmonotonic_time, durationname, result, outcome
:rejectedsystem_timename
:opensystem_time, timeoutname, from, outcome, forced¹
:half_opensystem_timename, from
:probingsystem_time, timeoutname, from, outcome
:closedsystem_timename, from, forced¹, restart¹

¹ Only present when the change was forced with Rexsilient.CircuitBreaker.force_open/1 or Rexsilient.CircuitBreaker.force_close/1, or caused by a manager restart. A forced :open has timeout: :infinity, in the metadata.

[:rexsilient, :retry, event]:

EventMeasurementsMetadata
:startmonotonic_time, system_timename, attempt
:stopmonotonic_time, durationname, attempt, result, outcome
:delaydelayname, attempt, outcome
:give_updurationname, attempt, outcome, reason

[:rexsilient, :fallback, event]:

EventMeasurementsMetadata
:startmonotonic_time, system_timename, outcome (the one replaced)
:stopmonotonic_time, durationname, outcome

Times and duration are in native time units, delay and timeout in milliseconds. result is :success or :failure, and outcome is a Rexsilient.Classify.outcome/0.

Example

:telemetry.attach(
  "log-open-breakers",
  [:rexsilient, :circuit_breaker, :open],
  fn _event, _measurements, %{name: name, from: from}, _config ->
    Logger.warning("breaker #{inspect(name)} opened from #{from}")
  end,
  nil
)

Handlers run in the calling process

Unlike other notifiers, it runs in the calling process, so handlers must be fast; see Process.