ExAtlas.Fly.Logs.Client (ExAtlas v0.5.0)

Copy Markdown View Source

HTTP client for the Fly Machines log API.

Fetches from GET https://api.machines.dev/v1/apps/{app_name}/logs and parses the NDJSON body into ExAtlas.Fly.Logs.LogEntry structs.

The base URL is overridable via config :ex_atlas, :fly, log_endpoint: "..." or the :base_url option (useful for Bypass in tests).

Summary

Functions

Fetches logs for app_name using token.

Fetches logs with a single 401-driven retry.

Returns the next start_time cursor value for pagination.

Functions

fetch_logs(app_name, token, opts \\ [])

@spec fetch_logs(String.t(), String.t(), keyword()) ::
  {:ok, [ExAtlas.Fly.Logs.LogEntry.t()]} | {:error, term()}

Fetches logs for app_name using token.

Options

  • :region — filter by Fly region code.
  • :instance — filter by machine instance id.
  • :start_time — integer nanoseconds-since-epoch, for pagination.
  • :base_url — override the endpoint (default: :ex_atlas, :fly, log_endpoint or https://api.machines.dev/v1/apps).
  • :timeout_ms — request timeout.
  • :http_client — optional (url, headers) -> {:ok, status, body} | {:error, reason} override. When omitted, uses Req.

fetch_logs_with_retry(app_name, opts \\ [])

@spec fetch_logs_with_retry(
  String.t(),
  keyword()
) :: {:ok, [ExAtlas.Fly.Logs.LogEntry.t()]} | {:error, term()}

Fetches logs with a single 401-driven retry.

If the server returns 401, the token is invalidated, a new one is acquired, and the fetch is retried once.

Options

next_start_time(entries)

@spec next_start_time([ExAtlas.Fly.Logs.LogEntry.t()]) :: non_neg_integer() | nil

Returns the next start_time cursor value for pagination.

Given a list of LogEntry structs, returns the max timestamp in nanoseconds plus 1 (to avoid re-fetching the last entry). Returns nil for an empty list.