Moov.Telemetry (Moov v1.0.0)

Copy Markdown View Source

Telemetry events emitted by this library, via the :telemetry library (a transitive dependency of Req, so nothing extra to install).

[:moov, :request, :start]

Emitted right before a request is sent (on every attempt, including retries).

measurementdescription
:system_timeSystem.system_time/0 when emitted
metadatadescription
:methodthe HTTP method, e.g. :post
:paththe request path, e.g. "/accounts"
:attemptwhich attempt this is, starting at 1

[:moov, :request, :stop]

Emitted after a request (successfully or not) finishes its final attempt - i.e. once, per logical call, after all retries are exhausted.

measurementdescription
:durationtotal time across all attempts, in :native units
metadatadescription
:methodthe HTTP method
:paththe request path
:statusthe HTTP status code, if a response was received
:error_typethe Moov.Error.type/0 atom, if the call failed
:attemptshow many attempts were made in total

[:moov, :request, :exception]

Emitted instead of :stop if building or sending the request raises.

[:moov, :retry]

Emitted once per retry, right before sleeping.

measurementdescription
:delay_mshow long this attempt will sleep before retrying
metadatadescription
:methodthe HTTP method
:paththe request path
:attemptthe attempt number that just failed
:errorthe Moov.Error that triggered the retry

Example attach call

:telemetry.attach(
  "log-moov-requests",
  [:moov, :request, :stop],
  fn _event, %{duration: duration}, metadata, _config ->
    Logger.info("Moov #{metadata.method} #{metadata.path} -> " <>
      "#{inspect(metadata.status || metadata.error_type)} in " <>
      "#{System.convert_time_unit(duration, :native, :millisecond)}ms")
  end,
  nil
)