Railsr.Telemetry (Railsr v1.0.0)

Copy Markdown View Source

Telemetry integration for the railsr client.

Every HTTP call emits three events:

EventWhen
[:railsr, :request, :start]Before the HTTP request is sent
[:railsr, :request, :stop]After a response is received (success or error)
[:railsr, :request, :exception]On unexpected exception

Event Measurements

:start

%{system_time: integer()}

:stop

%{duration: integer(), status: integer()}

:exception

%{duration: integer()}

Event Metadata

All events carry:

%{
  method: atom(),          # :get | :post | :put | :patch | :delete
  path: String.t(),        # "/v1/customer/ledgers"
  attempt: non_neg_integer(),
  library: :railsr
}

Attaching Metrics (Telemetry.Metrics)

# In your application's telemetry setup:
import Telemetry.Metrics

def metrics do
  [
    counter("railsr.request.stop.count", tags: [:method, :path]),
    summary("railsr.request.stop.duration",
      unit: {:native, :millisecond},
      tags: [:method, :path]
    ),
    counter("railsr.request.stop.error_count",
      keep: &match?(%{status: s} when s >= 400, &1),
      tags: [:method, :path]
    )
  ]
end

Summary

Functions

Attaches a simple Logger handler that logs every completed request. Useful during development.

Functions

attach_logger(level \\ :debug)

@spec attach_logger(Logger.level()) :: :ok | {:error, :already_exists}

Attaches a simple Logger handler that logs every completed request. Useful during development.

Railsr.Telemetry.attach_logger()