-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #466 from newrelic/vince/auto-error-backend
Use logger primary filter to hook into error reporting
- Loading branch information
Showing
13 changed files
with
90 additions
and
105 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
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,4 @@ | ||
import Config | ||
|
||
config :logger, | ||
handle_sasl_reports: true, | ||
backends: [NewRelic.ErrorLogger] | ||
|
||
if Mix.env() == :test, do: import_config("test.exs") | ||
if File.exists?("config/secret.exs"), do: import_config("secret.exs") |
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,62 @@ | ||
defmodule NewRelic.Error.LoggerFilter do | ||
@moduledoc false | ||
|
||
# Track errors by attaching a `:logger` primary filter | ||
# Always returns `:ignore` so we don't actually filter anything | ||
|
||
def add_filter() do | ||
:logger.add_primary_filter(__MODULE__, {&__MODULE__.filter/2, []}) | ||
end | ||
|
||
def remove_filter() do | ||
:logger.remove_primary_filter(__MODULE__) | ||
end | ||
|
||
def filter( | ||
%{ | ||
meta: %{error_logger: %{type: :crash_report}}, | ||
msg: {:report, %{report: [report | _]}} | ||
}, | ||
_opts | ||
) do | ||
if NewRelic.Transaction.Sidecar.tracking?() do | ||
NewRelic.Error.Reporter.CrashReport.report_error(:transaction, report) | ||
else | ||
NewRelic.Error.Reporter.CrashReport.report_error(:process, report) | ||
end | ||
|
||
:ignore | ||
end | ||
|
||
if NewRelic.Util.ConditionalCompile.match?("< 1.15.0") do | ||
def filter( | ||
%{ | ||
meta: %{error_logger: %{tag: :error_msg}}, | ||
msg: {:report, %{label: {_, :terminating}}} | ||
}, | ||
_opts | ||
) do | ||
:ignore | ||
end | ||
end | ||
|
||
def filter( | ||
%{ | ||
meta: %{error_logger: %{tag: :error_msg}}, | ||
msg: {:report, %{report: %{} = report}} | ||
}, | ||
_opts | ||
) do | ||
if NewRelic.Transaction.Sidecar.tracking?() do | ||
NewRelic.Error.Reporter.ErrorMsg.report_error(:transaction, report) | ||
else | ||
NewRelic.Error.Reporter.ErrorMsg.report_error(:process, report) | ||
end | ||
|
||
:ignore | ||
end | ||
|
||
def filter(_log, _opts) do | ||
:ignore | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
lib/new_relic/error/reporter.ex → lib/new_relic/error/reporter/crash_report.ex
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
22 changes: 8 additions & 14 deletions
22
lib/new_relic/error/metadata_reporter.ex → lib/new_relic/error/reporter/error_msg.ex
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 |
---|---|---|
@@ -1,44 +1,16 @@ | ||
defmodule NewRelic.ErrorLogger do | ||
@moduledoc """ | ||
Handle error reporting in elixir >= 1.15 | ||
""" | ||
@moduledoc false | ||
require Logger | ||
@behaviour :gen_event | ||
|
||
if NewRelic.Util.ConditionalCompile.match?(">= 1.15.0") do | ||
def init(opts) do | ||
Logger.add_translator({__MODULE__, :translator}) | ||
{:ok, opts} | ||
end | ||
else | ||
def init(opts) do | ||
{:ok, opts} | ||
end | ||
def init(_) do | ||
Logger.warning("`NewRelic.ErrorLogger` no longer needed, please remove it from :logger configuration") | ||
{:ok, nil} | ||
end | ||
|
||
def handle_call(_opts, state), do: {:ok, :ok, state} | ||
|
||
def handle_event(_opts, state), do: {:ok, state} | ||
|
||
def handle_info(_opts, state), do: {:ok, state} | ||
|
||
def code_change(_old_vsn, state, _extra), do: {:ok, state} | ||
|
||
if NewRelic.Util.ConditionalCompile.match?(">= 1.15.0") do | ||
def terminate(_reason, _state) do | ||
Logger.remove_translator({__MODULE__, :translator}) | ||
:ok | ||
end | ||
else | ||
def terminate(_reason, _state) do | ||
:ok | ||
end | ||
end | ||
|
||
# Don't log SASL progress reports | ||
def translator(_level, _message, _timestamp, {{caller, :progress}, _}) | ||
when caller in [:supervisor, :application_controller] do | ||
:skip | ||
end | ||
|
||
def translator(_level, _message, _timestamp, _metadata), do: :none | ||
def terminate(_reason, _state), do: :ok | ||
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
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