-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* RingBuffer * Basic working version * Added Collector * Adding error breadcrumb in notice * Fixing some specs, ignore DateTime in to_encodable * Added Utils.sanitize * Moved notice breadcrumb creation out of notice.new * Now sanitizing breadcrumb metadata * Filter breadcrumbs * Convert structs to Map in sanitizer * Dropped elixir 1.7 and added 1.9 to the matrix * Storing error breadcrumb * Basic setup for telemetry events * Added specs for telemetry * Updated docs
- Loading branch information
1 parent
6efbe99
commit c2dc311
Showing
27 changed files
with
821 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
language: elixir | ||
sudo: false | ||
elixir: | ||
- 1.7 | ||
- 1.8 | ||
- 1.9 | ||
otp_release: | ||
- 21.2 | ||
- 22.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
defmodule Honeybadger.Breadcrumbs.Breadcrumb do | ||
@moduledoc false | ||
|
||
@derive Jason.Encoder | ||
|
||
@type t :: %__MODULE__{ | ||
message: String.t(), | ||
category: String.t(), | ||
timestamp: DateTime.t(), | ||
metadata: map() | ||
} | ||
|
||
@type opts :: [{:metadata, map()} | {:category, String.t()}] | ||
@enforce_keys [:message, :category, :timestamp, :metadata] | ||
|
||
@default_category "custom" | ||
@default_metadata %{} | ||
|
||
defstruct [:message, :category, :timestamp, :metadata] | ||
|
||
@spec new(String.t(), opts()) :: t() | ||
def new(message, opts) do | ||
%__MODULE__{ | ||
message: message, | ||
category: opts[:category] || @default_category, | ||
timestamp: DateTime.utc_now(), | ||
metadata: opts[:metadata] || @default_metadata | ||
} | ||
end | ||
|
||
@spec from_error(any()) :: t() | ||
def from_error(error) do | ||
error = Exception.normalize(:error, error, []) | ||
|
||
%{__struct__: error_mod} = error | ||
|
||
new( | ||
Honeybadger.Utils.module_to_string(error_mod), | ||
metadata: %{message: error_mod.message(error)}, | ||
category: "error" | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
defmodule Honeybadger.Breadcrumbs.Collector do | ||
@moduledoc false | ||
|
||
@doc """ | ||
The Collector provides an interface for accessing and affecting the current | ||
set of breadcrumbs. Most operations are delegated to the supplied Buffer | ||
implementation. This is mainly for internal use. | ||
""" | ||
|
||
alias Honeybadger.Breadcrumbs.{RingBuffer, Breadcrumb} | ||
alias Honeybadger.Utils | ||
|
||
@buffer_impl RingBuffer | ||
@buffer_size 40 | ||
@metadata_key :hb_breadcrumbs | ||
|
||
@type t :: %{enabled: boolean(), trail: [Breadcrumb.t()]} | ||
|
||
@spec output() :: t() | ||
def output(), do: output(breadcrumbs()) | ||
|
||
@spec output(@buffer_impl.t()) :: t() | ||
def output(breadcrumbs) do | ||
%{ | ||
enabled: Honeybadger.get_env(:breadcrumbs_enabled), | ||
trail: @buffer_impl.to_list(breadcrumbs) | ||
} | ||
end | ||
|
||
@spec put(@buffer_impl.t(), Breadcrumb.t()) :: @buffer_impl.t() | ||
def put(breadcrumbs, breadcrumb) do | ||
@buffer_impl.add( | ||
breadcrumbs, | ||
Map.update(breadcrumb, :metadata, %{}, &Utils.sanitize(&1, max_depth: 1)) | ||
) | ||
end | ||
|
||
@spec add(Breadcrumb.t()) :: :ok | ||
def add(breadcrumb) do | ||
if Honeybadger.get_env(:breadcrumbs_enabled) do | ||
Logger.metadata([{@metadata_key, put(breadcrumbs(), breadcrumb)}]) | ||
end | ||
|
||
:ok | ||
end | ||
|
||
@spec clear() :: :ok | ||
def clear() do | ||
Logger.metadata([{@metadata_key, @buffer_impl.new(@buffer_size)}]) | ||
end | ||
|
||
def metadata_key(), do: @metadata_key | ||
|
||
@spec breadcrumbs() :: @buffer_impl.t() | ||
def breadcrumbs() do | ||
Logger.metadata() | ||
|> Keyword.get(@metadata_key, @buffer_impl.new(@buffer_size)) | ||
end | ||
end |
Oops, something went wrong.