Packages
honeybadger
0.6.0
0.28.0
0.27.0
0.26.0
0.25.0
0.24.1
0.24.0
0.23.0
0.22.1
0.22.0
0.21.0
0.20.0
0.19.0
0.18.1
0.18.0
0.17.0
0.16.4
0.16.3
0.16.2
0.16.1
0.16.0
0.15.0
0.14.1
0.14.0
0.13.1
0.13.0
0.12.1
0.12.0
0.11.0
0.10.3
0.10.2
0.10.1
0.10.0
0.9.0
0.8.0
0.7.0
0.7.0-beta
0.6.3
0.6.2
0.6.1
0.6.0
0.5.0
0.4.0
0.3.1
0.3.0
0.2.0
0.1.2
0.1.1
0.1.0
Elixir client, Plug and error_logger for integrating with the Honeybadger.io exception tracker"
Current section
Files
Jump to
Current section
Files
lib/honeybadger/client.ex
defmodule Honeybadger.Client do
alias Poison, as: JSON
defstruct [:environment_name, :headers, :hostname, :origin]
@metrics_endpoint "/v1/metrics"
@notices_endpoint "/v1/notices"
def new do
origin = Application.get_env(:honeybadger, :origin)
api_key = Application.get_env(:honeybadger, :api_key)
env_name = Application.get_env(:honeybadger, :environment_name)
hostname = Application.get_env(:honeybadger, :hostname)
%__MODULE__{origin: origin,
headers: headers(api_key),
environment_name: env_name,
hostname: hostname}
end
def send_metric(%__MODULE__{} = client, metric, http_mod \\ HTTPoison) do
body = JSON.encode!(%{
environment: client.environment_name,
hostname: client.hostname,
metrics: metric
})
http_mod.post(
client.origin <> @metrics_endpoint, body, client.headers
)
end
def send_notice(%__MODULE__{} = client, metric, http_mod \\ HTTPoison) do
body = JSON.encode!(metric)
http_mod.post(
client.origin <> @notices_endpoint, body, client.headers
)
end
defp headers(api_key) do
[{"Accept", "application/json"},
{"Content-Type", "application/json"},
{"X-API-Key", api_key}]
end
end