Errorgap (errorgap v0.3.0)

Copy Markdown View Source

Elixir notifier for Errorgap. Configure via Application env, then call Errorgap.notify/2 directly, attach Errorgap.Plug to your Phoenix endpoint, or wire Errorgap.LoggerHandler into :logger for handler-style capture of crash reports and high-severity logs.

Beyond exceptions, the SDK ships source-aware backtraces, nested causes, breadcrumbs (add_breadcrumb/3), structured logs (log/3), and APM transactions (notify_transaction/2).

Summary

Functions

Record a diagnostic breadcrumb attached to subsequent notices built in this process as context.breadcrumbs.

Clear the current process's breadcrumbs.

The id of the transaction this process is running in, if any.

Block until all queued notices have been delivered. Use during graceful shutdown.

Deliver a structured log line at the given level with an optional source.

Report an exception or string error to Errorgap. Returns :ok when the notice is queued or successfully delivered, {:error, reason} otherwise.

Run fun as part of a transaction: errors reported from this process while it runs carry its id as context.transaction_id, so errorgap shows the error a request actually raised on its trace.

Functions

add_breadcrumb(message, category \\ nil, metadata \\ %{})

@spec add_breadcrumb(binary(), binary() | atom() | nil, map()) :: :ok

Record a diagnostic breadcrumb attached to subsequent notices built in this process as context.breadcrumbs.

clear_breadcrumbs()

@spec clear_breadcrumbs() :: :ok

Clear the current process's breadcrumbs.

current_transaction_id()

@spec current_transaction_id() :: binary() | nil

The id of the transaction this process is running in, if any.

flush(timeout \\ 5000)

@spec flush(timeout()) :: :ok

Block until all queued notices have been delivered. Use during graceful shutdown.

log(message, level \\ "info", source \\ nil, opts \\ [])

@spec log(binary(), binary() | atom(), binary() | nil, keyword()) ::
  :ok | {:error, term()} | {:ok, map()}

Deliver a structured log line at the given level with an optional source.

notify(error, opts \\ [])

@spec notify(
  Exception.t() | binary(),
  keyword()
) :: :ok | {:error, term()} | {:ok, map()}

Report an exception or string error to Errorgap. Returns :ok when the notice is queued or successfully delivered, {:error, reason} otherwise.

Options include :stacktrace, :context, :environment, :session, :params, :cause (an exception whose :cause chain is flattened into context.causes), :breadcrumbs, and :sync.

notify_transaction(transaction, opts \\ [])

@spec notify_transaction(
  map(),
  keyword()
) :: :ok | {:error, term()} | {:ok, map()}

Deliver an APM transaction. Build one with Errorgap.Transaction.web/4 or Errorgap.Transaction.job/3.

version()

with_transaction(transaction_or_id, fun)

@spec with_transaction(map() | binary(), (-> result)) :: result when result: any()

Run fun as part of a transaction: errors reported from this process while it runs carry its id as context.transaction_id, so errorgap shows the error a request actually raised on its trace.

transaction = Errorgap.Transaction.web("GET", "/orders/{id}", "/orders/7")
result = Errorgap.with_transaction(transaction, fn -> handle(conn) end)
Errorgap.notify_transaction(Map.merge(transaction, %{"status_code" => 200}))