Packages
EndPointBlank Elixir client library: authorization plus request/response/error/log ingestion (with masking, batching, timeouts, and a bounded queue) — also used for self-monitoring.
Current section
Files
Jump to
Current section
Files
lib/end_point_blank/writers/direct_writer.ex
defmodule EndPointBlank.Writers.DirectWriter do
@moduledoc "Synchronously POSTs a payload batch to the EndPointBlank API."
require Logger
alias EndPointBlank.{Authorization, Http}
@url_builders %{
requests: :requests_url,
responses: :responses_url,
logs: :logs_url,
errors: :errors_url
}
def write(url_key, payloads) when is_list(payloads) do
url = apply(EndPointBlank.Config, @url_builders[url_key] || :errors_url, [])
auth = Authorization.header()
body = %{payload: payloads}
case Http.post(url, body, auth) do
{:ok, %Req.Response{status: s}} when s in 200..299 ->
:ok
{:ok, %Req.Response{status: s, body: b}} ->
Logger.warning("[EndPointBlank] Write to #{url_key} failed: status=#{s} body=#{inspect(b)}")
:error
{:error, reason} ->
Logger.warning("[EndPointBlank] Write to #{url_key} error: #{inspect(reason)}")
:error
end
end
end