Triple.Telemetry (triple v1.0.0)

Copy Markdown View Source

:telemetry events emitted by this library. Attach handlers the usual way to get logging, metrics, or tracing for free.

Events

  • [:triple, :request, :start] — emitted before each HTTP call. Measurements: %{system_time: integer}. Metadata: %{method: atom, path: String.t(), environment: :production | :sandbox}.

  • [:triple, :request, :stop] — emitted after a call completes, whether it succeeded or failed with an HTTP/validation error. Measurements: %{duration: integer} (native time unit — see System.convert_time_unit/3). Metadata: same as :start, plus :result (:ok or :error).

  • [:triple, :request, :exception] — emitted if the call raises unexpectedly (an actual crash, not an HTTP error response — those are reported via :stop with result: :error). Metadata: same as :start, plus :kind, :reason, :stacktrace.

Example

:telemetry.attach(
  "triple-logger",
  [:triple, :request, :stop],
  fn _event, %{duration: duration}, metadata, _config ->
    ms = System.convert_time_unit(duration, :native, :millisecond)
    Logger.info("Triple #{metadata.method} #{metadata.path} -> #{metadata.result} (#{ms}ms)")
  end,
  nil
)