Packages
ex_kargo_neuron
0.1.0
Common utils and Configuration for `Neuron` (GraphQL Client Library) in Kargo system
Current section
Files
Jump to
Current section
Files
lib/ex_kargo/neuron/connection.ex
defmodule ExKargo.Neuron.Connection do
@moduledoc """
`Neuron.Connection` implementation which extend default `Neuron.Connection.Http` with automatic Header 'X-Request-Id' that `Phoenix` give
"""
@behaviour Neuron.Connection
alias Neuron.Config
require Logger
@impl Neuron.Connection
def call(body, options) do
options = modify_headers(options)
Neuron.Connection.Http.call(body, options)
end
defp modify_headers(options) do
if Logger.metadata[:request_id] != nil do
headers = headers(options)
modified_headers = Keyword.put(headers, :"X-Request-ID", Logger.metadata[:request_id])
Keyword.put(options, :headers, modified_headers)
else
options
end
end
defp headers(options), do: Keyword.get(options, :headers, Config.get(:headers) || [])
end