Skip to content

Commit c56373c

Browse files
authored
Merge pull request #426 from letscolife/additional-elixir-115-updates
Additional elixir 1.15 compatibility
2 parents 5441301 + 6d915ef commit c56373c

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ config :new_relic_agent,
6363
httpc_request_options: [connect_timeout: 5000]
6464
```
6565

66+
#### For Elixir 1.15 and higher
67+
68+
Due to changes in the Elixir 1.15 Logger, additional logger configuration is needed for NewRelic to capture all errors. Update your logger configuration by setting `handle_sasl_reports` to `true` and adding `NewRelic.ErrorLogger` to your logger backends.
69+
70+
```elixir
71+
config :logger,
72+
handle_sasl_reports: true,
73+
backends: [:console, NewRelic.ErrorLogger]
74+
```
75+
6676
## Telemetry-based Instrumentation
6777

6878
Some common Elixir packages are auto-instrumented via [`telemetry`](https://github.com/beam-telemetry/telemetry)

config/config.exs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Config
22

3-
config :logger, handle_sasl_reports: true
3+
config :logger,
4+
handle_sasl_reports: true,
5+
backends: [NewRelic.ErrorLogger]
46

57
if Mix.env() == :test, do: import_config("test.exs")
68
if File.exists?("config/secret.exs"), do: import_config("secret.exs")

lib/new_relic/error/logger_handler.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule NewRelic.Error.LoggerHandler do
1616
NewRelic.Error.Reporter.report_error(:process, report)
1717
end
1818

19-
:none
19+
:skip
2020
end
2121

2222
def translator(_level, :error, _timestamp, {_, %{args: _, function: _}} = metadata) do

lib/new_relic/error_logger.ex

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
defmodule NewRelic.ErrorLogger do
2+
@moduledoc """
3+
Handle error reporting in elixir >= 1.15
4+
"""
5+
@behaviour :gen_event
6+
7+
import NewRelic.ConditionalCompile
8+
9+
def init(opts) do
10+
after_elixir_version(
11+
"1.15.0",
12+
Logger.add_translator({__MODULE__, :translator})
13+
)
14+
15+
{:ok, opts}
16+
end
17+
18+
def handle_call(_opts, state), do: {:ok, :ok, state}
19+
20+
def handle_event(_opts, state), do: {:ok, state}
21+
22+
def handle_info(_opts, state), do: {:ok, state}
23+
24+
def code_change(_old_vsn, state, _extra), do: {:ok, state}
25+
26+
def terminate(_reason, _state) do
27+
after_elixir_version(
28+
"1.15.0",
29+
Logger.remove_translator({__MODULE__, :translator})
30+
)
31+
32+
:ok
33+
end
34+
35+
# Don't log SASL progress reports
36+
def translator(_level, _message, _timestamp, {{caller, :progress}, _})
37+
when caller in [:supervisor, :application_controller] do
38+
:skip
39+
end
40+
41+
def translator(_level, _message, _timestamp, _metadata), do: :none
42+
end

0 commit comments

Comments
 (0)