Paysafe.Telemetry (Paysafe v1.0.0)

Copy Markdown View Source

Telemetry instrumentation for all Paysafe API calls.

Events

Every API call emits two events:

  • [:paysafe, :request, :start] — emitted before the HTTP call.
  • [:paysafe, :request, :stop] — emitted after the HTTP call completes.
  • [:paysafe, :request, :exception] — emitted if the call raises.

The prefix [:paysafe] can be customised via :telemetry_prefix in config.

Measurements

:stop events include:

  • :duration — wall time in native units. Use :telemetry.convert_duration/2.
  • :http_status — integer HTTP status code.

Metadata

All events include:

  • :method — HTTP method atom (:get, :post, etc.).
  • :path — Request path string.
  • :api — Atom identifying the Paysafe API (:payments, :scheduler, etc.).
  • :operation — String name of the SDK operation.
  • :oktrue on success, false on error (:stop only).
  • :error%Paysafe.Error{} on failure (:stop only, if applicable).

Example – attaching a handler

:telemetry.attach(
  "log-paysafe-requests",
  [:paysafe, :request, :stop],
  fn _event, %{duration: d}, %{operation: op, ok: ok}, _cfg ->
    ms = System.convert_time_unit(d, :native, :millisecond)
    status = if ok, do: "ok", else: "error"
    Logger.info("paysafe #{op} #{status} #{ms}ms")
  end,
  nil
)