Packages
raygun
0.1.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.0
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.0.45
0.0.44
0.0.43
0.0.42
0.0.41
0.0.40
0.0.39
0.0.38
0.0.37
0.0.36
0.0.35
0.0.34
0.0.33
0.0.32
0.0.31
0.0.30
0.0.29
0.0.28
0.0.27
0.0.26
0.0.25
0.0.24
0.0.23
0.0.22
0.0.21
0.0.20
0.0.19
0.0.18
0.0.17
0.0.16
0.0.15
0.0.14
0.0.13
0.0.12
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
Send errors in your application to Raygun. Raygun captures all your application errors in one place. It can be used as a Plug, via Logger and/or programmatically.
Current section
Files
Jump to
Current section
Files
lib/raygun.ex
defmodule Raygun do
@moduledoc """
Send errors to Raygun. Errors can be captured in three different ways.
1. Any errors that are logged
2. Any exceptions that occur in a Plug
3. Programmatically
"""
@api_endpoint "https://api.raygun.io"
@doc """
Reports a string message. This function is used by the Raygun.Logger but it
can also be used to report any string message.
"""
def report_message(msg, opts \\ []) do
msg
|> Raygun.Format.message_payload(opts)
|> Poison.encode!
|> send_report
end
@doc """
Convenience function that captures the most recent stacktrace and reports it
along with the exception. NOTE: it is the responsiblity of the caller to
ensure that the most recent stacktrace is the one associated with the
exception.
"""
def report_exception(exception, opts \\ []) do
System.stacktrace
|> report_stacktrace(exception, opts)
end
@doc """
Reports an exception and its corresponding stacktrace to Raygun.
"""
def report_stacktrace(stacktrace, exception, opts \\ []) do
stacktrace
|> Raygun.Format.stacktrace_payload(exception, opts)
|> Poison.encode!
|> send_report
end
@doc """
Reports an exception and its corresponding stacktrace to Raygun. Additionally
this captures some additional information about the environment in which
the exception occurred by retrieving some state from the Plug Conn.
"""
def report_plug(conn, stacktrace, exception, opts \\ []) do
conn
|> Raygun.Format.conn_payload(stacktrace, exception, opts)
|> Poison.encode!
|> send_report
end
@doc """
Send an error to Raygun.
"""
def send_report(json) do
spawn fn -> send_report_to_raygun(json) end
end
def send_report_to_raygun(json) do
headers = %{
"Content-Type": "application/json; charset=utf-8",
"Accept": "application/json",
"User-Agent": "Elixir Client",
"X-ApiKey": Raygun.Util.get_env(:raygun, :api_key)
}
# if we fail to send an error to Raygun that is ok for now...
spawn fn ->
{:ok, response} = HTTPoison.post(@api_endpoint <> "/entries", json, headers)
%HTTPoison.Response{status_code: 202} = response
end
end
end