Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional elixir 1.15 compatibility #426

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ config :new_relic_agent,
httpc_request_options: [connect_timeout: 5000]
```

#### For Elixir 1.15 and higher

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.

```elixir
config :logger,
handle_sasl_reports: true,
backends: [:console, NewRelic.ErrorLogger]
```

## Telemetry-based Instrumentation

Some common Elixir packages are auto-instrumented via [`telemetry`](https://github.com/beam-telemetry/telemetry)
Expand Down
4 changes: 3 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Config

config :logger, handle_sasl_reports: true
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")
2 changes: 1 addition & 1 deletion lib/new_relic/error/logger_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule NewRelic.Error.LoggerHandler do
NewRelic.Error.Reporter.report_error(:process, report)
end

:none
:skip
end

def translator(_level, :error, _timestamp, {_, %{args: _, function: _}} = metadata) do
Expand Down
42 changes: 42 additions & 0 deletions lib/new_relic/error_logger.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
defmodule NewRelic.ErrorLogger do
@moduledoc """
Handle error reporting in elixir >= 1.15
"""
@behaviour :gen_event

import NewRelic.ConditionalCompile

def init(opts) do
after_elixir_version(
"1.15.0",
Logger.add_translator({__MODULE__, :translator})
)

{:ok, opts}
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}

def terminate(_reason, _state) do
after_elixir_version(
"1.15.0",
Logger.remove_translator({__MODULE__, :translator})
)

:ok
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
end
Loading