diff --git a/lib/appsignal.ex b/lib/appsignal.ex index ee32301c1..598809b6f 100644 --- a/lib/appsignal.ex +++ b/lib/appsignal.ex @@ -8,14 +8,11 @@ defmodule Appsignal do helper functions for sending metrics to AppSignal. """ - require Mix.Appsignal.Utils - - @os Mix.Appsignal.Utils.compile_env(:appsignal, :os_internal, :os) + @os Application.compile_env(:appsignal, :os_internal, :os) use Application alias Appsignal.Config require Logger - import Appsignal.Utils, only: [info: 1, warning: 1] @doc false def start(_type, _args) do @@ -87,7 +84,7 @@ defmodule Appsignal do def initialize do case {Config.initialize(), Config.configured_as_active?()} do {_, false} -> - info("AppSignal disabled.") + Logger.info("AppSignal disabled.") {:ok, true} -> Appsignal.IntegrationLogger.debug("AppSignal starting.") @@ -101,7 +98,7 @@ defmodule Appsignal do end {{:error, :invalid_config}, true} -> - warning( + Logger.warning( "Warning: No valid AppSignal configuration found, continuing with " <> "AppSignal metrics disabled." ) diff --git a/lib/appsignal/absinthe.ex b/lib/appsignal/absinthe.ex index f35450c61..3c99133ca 100644 --- a/lib/appsignal/absinthe.ex +++ b/lib/appsignal/absinthe.ex @@ -1,13 +1,11 @@ defmodule Appsignal.Absinthe do - require Appsignal.Utils + require Logger - @tracer Appsignal.Utils.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) - @span Appsignal.Utils.compile_env(:appsignal, :appsignal_span, Appsignal.Span) + @tracer Application.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) + @span Application.compile_env(:appsignal, :appsignal_span, Appsignal.Span) @moduledoc false - import Appsignal.Utils, only: [warning: 1] - def attach do handlers = %{ [:absinthe, :execute, :operation, :start] => &__MODULE__.absinthe_execute_operation_start/4, @@ -34,7 +32,9 @@ defmodule Appsignal.Absinthe do :ok {_, {:error, _} = error} -> - warning("Appsignal.Absinthe not attached to #{inspect(event)}: #{inspect(error)}") + Logger.warning( + "Appsignal.Absinthe not attached to #{inspect(event)}: #{inspect(error)}" + ) error end diff --git a/lib/appsignal/config.ex b/lib/appsignal/config.ex index 0333c431b..680f105b2 100644 --- a/lib/appsignal/config.ex +++ b/lib/appsignal/config.ex @@ -2,7 +2,8 @@ defmodule Appsignal.Config do @moduledoc false alias Appsignal.Nif alias Appsignal.Utils.FileSystem - import Appsignal.Utils, only: [warning: 1] + + require Logger @default_config %{ active: false, @@ -64,7 +65,7 @@ defmodule Appsignal.Config do config = Map.merge(config, sources[:override]) if !empty?(config[:working_dir_path]) do - warning(fn -> + Logger.warning(fn -> "'working_dir_path' is deprecated, please use " <> "'working_directory_path' instead and specify the " <> "full path to the working directory" @@ -234,7 +235,7 @@ defmodule Appsignal.Config do "all" unknown -> - warning( + Logger.warning( "Unknown value #{inspect(unknown)} for report_oban_errors config " <> ~s(option. Valid values are "discard", "none", "all". ) <> ~s(Defaulting to "all".) diff --git a/lib/appsignal/demo.ex b/lib/appsignal/demo.ex index 053c9262c..7653d8f26 100644 --- a/lib/appsignal/demo.ex +++ b/lib/appsignal/demo.ex @@ -7,9 +7,7 @@ defmodule Appsignal.Demo do @moduledoc false import Appsignal.Instrumentation, only: [instrument: 2, instrument: 3] - require Appsignal.Utils - - @span Appsignal.Utils.compile_env(:appsignal, :appsignal_span, Appsignal.Span) + @span Application.compile_env(:appsignal, :appsignal_span, Appsignal.Span) def send_performance_sample do instrument("DemoController#hello", "call.phoenix", fn span -> diff --git a/lib/appsignal/diagnose/agent.ex b/lib/appsignal/diagnose/agent.ex index e4cd042aa..debcdf272 100644 --- a/lib/appsignal/diagnose/agent.ex +++ b/lib/appsignal/diagnose/agent.ex @@ -1,9 +1,7 @@ defmodule Appsignal.Diagnose.Agent do @moduledoc false - require Appsignal.Utils - - @nif Appsignal.Utils.compile_env(:appsignal, :appsignal_nif, Appsignal.Nif) + @nif Application.compile_env(:appsignal, :appsignal_nif, Appsignal.Nif) def report do if @nif.loaded?() do diff --git a/lib/appsignal/diagnose/host.ex b/lib/appsignal/diagnose/host.ex index ff22f79f8..10c093016 100644 --- a/lib/appsignal/diagnose/host.ex +++ b/lib/appsignal/diagnose/host.ex @@ -1,10 +1,8 @@ defmodule Appsignal.Diagnose.Host do @moduledoc false - require Appsignal.Utils - - @system Appsignal.Utils.compile_env(:appsignal, :appsignal_system, Appsignal.System) - @nif Appsignal.Utils.compile_env(:appsignal, :appsignal_nif, Appsignal.Nif) + @system Application.compile_env(:appsignal, :appsignal_system, Appsignal.System) + @nif Application.compile_env(:appsignal, :appsignal_nif, Appsignal.Nif) def info do {_, os} = :os.type() diff --git a/lib/appsignal/diagnose/library.ex b/lib/appsignal/diagnose/library.ex index 7143a0c4c..e1a8f9c85 100644 --- a/lib/appsignal/diagnose/library.ex +++ b/lib/appsignal/diagnose/library.ex @@ -1,11 +1,9 @@ defmodule Appsignal.Diagnose.Library do @moduledoc false - require Appsignal.Utils - @appsignal_version Mix.Project.config()[:version] @agent_version Appsignal.Agent.version() - @nif Appsignal.Utils.compile_env(:appsignal, :appsignal_nif, Appsignal.Nif) + @nif Application.compile_env(:appsignal, :appsignal_nif, Appsignal.Nif) def info do %{ diff --git a/lib/appsignal/ecto.ex b/lib/appsignal/ecto.ex index 4de815035..d655f22fa 100644 --- a/lib/appsignal/ecto.ex +++ b/lib/appsignal/ecto.ex @@ -1,9 +1,9 @@ defmodule Appsignal.Ecto do - require Appsignal.Utils + require Logger - @tracer Appsignal.Utils.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) - @span Appsignal.Utils.compile_env(:appsignal, :appsignal_span, Appsignal.Span) - import Appsignal.Utils, only: [module_name: 1, warning: 1] + @tracer Application.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) + @span Application.compile_env(:appsignal, :appsignal_span, Appsignal.Span) + import Appsignal.Utils, only: [module_name: 1] @doc """ Attaches `Appsignal.Ecto` to the Ecto telemetry channel configured in the @@ -34,7 +34,7 @@ defmodule Appsignal.Ecto do :ok {:error, _} = error -> - warning("Appsignal.Ecto not attached to #{inspect(event)}: #{inspect(error)}") + Logger.warning("Appsignal.Ecto not attached to #{inspect(event)}: #{inspect(error)}") error end diff --git a/lib/appsignal/ecto_repo.ex b/lib/appsignal/ecto_repo.ex index e78d6819c..ba0fc14c3 100644 --- a/lib/appsignal/ecto_repo.ex +++ b/lib/appsignal/ecto_repo.ex @@ -1,6 +1,5 @@ defmodule Appsignal.Ecto.Repo do - require Appsignal.Utils - @ecto_repo Appsignal.Utils.compile_env(:appsignal, :ecto_repo, Ecto.Repo) + @ecto_repo Application.compile_env(:appsignal, :ecto_repo, Ecto.Repo) defmacro __using__(opts) do quote do diff --git a/lib/appsignal/error/backend.ex b/lib/appsignal/error/backend.ex index 82cab1e0b..69e5e61a5 100644 --- a/lib/appsignal/error/backend.ex +++ b/lib/appsignal/error/backend.ex @@ -1,21 +1,19 @@ defmodule Appsignal.Error.Backend do @moduledoc false - require Appsignal.Utils + require Logger - @tracer Appsignal.Utils.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) - @span Appsignal.Utils.compile_env(:appsignal, :appsignal_span, Appsignal.Span) + @tracer Application.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) + @span Application.compile_env(:appsignal, :appsignal_span, Appsignal.Span) @behaviour :gen_event - import Appsignal.Utils, only: [warning: 1] - def init(opts), do: {:ok, opts} def attach do case Logger.add_backend(Appsignal.Error.Backend) do {:error, error} -> - warning("Appsignal.Error.Backend not attached to Logger: #{error}") + Logger.warning("Appsignal.Error.Backend not attached to Logger: #{error}") :error _ -> diff --git a/lib/appsignal/finch.ex b/lib/appsignal/finch.ex index 6c6bb32ae..a4f190a30 100644 --- a/lib/appsignal/finch.ex +++ b/lib/appsignal/finch.ex @@ -1,13 +1,11 @@ defmodule Appsignal.Finch do - require Appsignal.Utils + require Logger - @tracer Appsignal.Utils.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) - @span Appsignal.Utils.compile_env(:appsignal, :appsignal_span, Appsignal.Span) + @tracer Application.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) + @span Application.compile_env(:appsignal, :appsignal_span, Appsignal.Span) @moduledoc false - import Appsignal.Utils, only: [warning: 1] - def attach do handlers = %{ [:finch, :request, :start] => &__MODULE__.finch_request_start/4, @@ -23,7 +21,7 @@ defmodule Appsignal.Finch do :ok {:error, _} = error -> - warning("Appsignal.Finch not attached to #{inspect(event)}: #{inspect(error)}") + Logger.warning("Appsignal.Finch not attached to #{inspect(event)}: #{inspect(error)}") error end diff --git a/lib/appsignal/heartbeat.ex b/lib/appsignal/heartbeat.ex index 89f2cecf4..ffe02055a 100644 --- a/lib/appsignal/heartbeat.ex +++ b/lib/appsignal/heartbeat.ex @@ -1,9 +1,8 @@ defmodule Appsignal.Heartbeat do alias __MODULE__ alias Appsignal.Heartbeat.Event - require Appsignal.Utils - @transmitter Appsignal.Utils.compile_env( + @transmitter Application.compile_env( :appsignal, :appsignal_transmitter, Appsignal.Transmitter diff --git a/lib/appsignal/instrumentation.ex b/lib/appsignal/instrumentation.ex index cb1127829..ac05665f2 100644 --- a/lib/appsignal/instrumentation.ex +++ b/lib/appsignal/instrumentation.ex @@ -1,8 +1,6 @@ defmodule Appsignal.Instrumentation do - require Appsignal.Utils - - @tracer Appsignal.Utils.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) - @span Appsignal.Utils.compile_env(:appsignal, :appsignal_span, Appsignal.Span) + @tracer Application.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) + @span Application.compile_env(:appsignal, :appsignal_span, Appsignal.Span) @spec instrument(function()) :: any() @doc false diff --git a/lib/appsignal/instrumentation/decorators.ex b/lib/appsignal/instrumentation/decorators.ex index 58c291cbe..40b294dd0 100644 --- a/lib/appsignal/instrumentation/decorators.ex +++ b/lib/appsignal/instrumentation/decorators.ex @@ -1,9 +1,7 @@ defmodule Appsignal.Instrumentation.Decorators do @moduledoc false - require Appsignal.Utils - - @span Appsignal.Utils.compile_env(:appsignal, :appsignal_span, Appsignal.Span) + @span Application.compile_env(:appsignal, :appsignal_span, Appsignal.Span) use Decorator.Define, instrument: 0, diff --git a/lib/appsignal/integration_logger.ex b/lib/appsignal/integration_logger.ex index ec94061d4..67180b230 100644 --- a/lib/appsignal/integration_logger.ex +++ b/lib/appsignal/integration_logger.ex @@ -1,8 +1,6 @@ defmodule Appsignal.IntegrationLogger do - require Appsignal.Utils - - @io Appsignal.Utils.compile_env(:appsignal, :io, IO) - @file_module Appsignal.Utils.compile_env(:appsignal, :file, File) + @io Application.compile_env(:appsignal, :io, IO) + @file_module Application.compile_env(:appsignal, :file, File) @log_levels [:trace, :debug, :info, :warn, :error] diff --git a/lib/appsignal/logger.ex b/lib/appsignal/logger.ex index 0d027ebb2..478206e57 100644 --- a/lib/appsignal/logger.ex +++ b/lib/appsignal/logger.ex @@ -1,7 +1,5 @@ defmodule Appsignal.Logger do - require Appsignal.Utils - - @nif Appsignal.Utils.compile_env(:appsignal, :appsignal_tracer_nif, Appsignal.Nif) + @nif Application.compile_env(:appsignal, :appsignal_tracer_nif, Appsignal.Nif) @type log_level :: :debug | :info | :notice | :warning | :error | :critical | :alert | :emergency diff --git a/lib/appsignal/monitor.ex b/lib/appsignal/monitor.ex index 09e866a06..ea934adcd 100644 --- a/lib/appsignal/monitor.ex +++ b/lib/appsignal/monitor.ex @@ -1,10 +1,8 @@ defmodule Appsignal.Monitor do @moduledoc false - require Appsignal.Utils - - @deletion_delay Appsignal.Utils.compile_env(:appsignal, :deletion_delay, 5_000) - @sync_interval Appsignal.Utils.compile_env(:appsignal, :sync_interval, 60_000) + @deletion_delay Application.compile_env(:appsignal, :deletion_delay, 5_000) + @sync_interval Application.compile_env(:appsignal, :sync_interval, 60_000) use GenServer alias Appsignal.Tracer diff --git a/lib/appsignal/oban.ex b/lib/appsignal/oban.ex index 0cc27db16..1492b16d0 100644 --- a/lib/appsignal/oban.ex +++ b/lib/appsignal/oban.ex @@ -1,14 +1,12 @@ defmodule Appsignal.Oban do - require Appsignal.Utils + require Logger - @tracer Appsignal.Utils.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) - @span Appsignal.Utils.compile_env(:appsignal, :appsignal_span, Appsignal.Span) - @appsignal Appsignal.Utils.compile_env(:appsignal, :appsignal, Appsignal) + @tracer Application.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) + @span Application.compile_env(:appsignal, :appsignal_span, Appsignal.Span) + @appsignal Application.compile_env(:appsignal, :appsignal, Appsignal) @moduledoc false - import Appsignal.Utils, only: [warning: 1] - def attach do exception_handler = case Appsignal.Config.report_oban_errors() do @@ -42,7 +40,7 @@ defmodule Appsignal.Oban do :ok {_, {:error, _} = error} -> - warning("Appsignal.Oban not attached to #{inspect(event)}: #{inspect(error)}") + Logger.warning("Appsignal.Oban not attached to #{inspect(event)}: #{inspect(error)}") error end diff --git a/lib/appsignal/probes/erlang_probe.ex b/lib/appsignal/probes/erlang_probe.ex index aadcfedcf..b87825168 100644 --- a/lib/appsignal/probes/erlang_probe.ex +++ b/lib/appsignal/probes/erlang_probe.ex @@ -1,6 +1,5 @@ defmodule Appsignal.Probes.ErlangProbe do @moduledoc false - require Appsignal.Utils def call(sample \\ nil) do next_sample = sample_schedulers() diff --git a/lib/appsignal/probes/probes.ex b/lib/appsignal/probes/probes.ex index 844e39384..b724f9edf 100644 --- a/lib/appsignal/probes/probes.ex +++ b/lib/appsignal/probes/probes.ex @@ -2,9 +2,8 @@ defmodule Appsignal.Probes do @moduledoc false use GenServer require Logger - require Appsignal.Utils - @integration_logger Appsignal.Utils.compile_env( + @integration_logger Application.compile_env( :appsignal, :appsignal_integration_logger, Appsignal.IntegrationLogger diff --git a/lib/appsignal/span.ex b/lib/appsignal/span.ex index 982d32530..fd67c1880 100644 --- a/lib/appsignal/span.ex +++ b/lib/appsignal/span.ex @@ -3,9 +3,7 @@ defmodule Appsignal.Span do defstruct [:reference, :pid] - require Appsignal.Utils - - @nif Appsignal.Utils.compile_env(:appsignal, :appsignal_tracer_nif, Appsignal.Nif) + @nif Application.compile_env(:appsignal, :appsignal_tracer_nif, Appsignal.Nif) @type t() :: %__MODULE__{ reference: reference(), diff --git a/lib/appsignal/tesla.ex b/lib/appsignal/tesla.ex index bdf8894dc..5f62ad01e 100644 --- a/lib/appsignal/tesla.ex +++ b/lib/appsignal/tesla.ex @@ -1,13 +1,11 @@ defmodule Appsignal.Tesla do - require Appsignal.Utils + require Logger - @tracer Appsignal.Utils.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) - @span Appsignal.Utils.compile_env(:appsignal, :appsignal_span, Appsignal.Span) + @tracer Application.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer) + @span Application.compile_env(:appsignal, :appsignal_span, Appsignal.Span) @moduledoc false - import Appsignal.Utils, only: [warning: 1] - def attach do handlers = %{ [:tesla, :request, :start] => &__MODULE__.tesla_request_start/4, @@ -23,7 +21,7 @@ defmodule Appsignal.Tesla do :ok {:error, _} = error -> - warning("Appsignal.Tesla not attached to #{inspect(event)}: #{inspect(error)}") + Logger.warning("Appsignal.Tesla not attached to #{inspect(event)}: #{inspect(error)}") error end diff --git a/lib/appsignal/tracer.ex b/lib/appsignal/tracer.ex index 44dc83df3..f5c8f5bed 100644 --- a/lib/appsignal/tracer.ex +++ b/lib/appsignal/tracer.ex @@ -1,9 +1,7 @@ defmodule Appsignal.Tracer do alias Appsignal.Span - require Appsignal.Utils - - @monitor Appsignal.Utils.compile_env(:appsignal, :appsignal_monitor, Appsignal.Monitor) + @monitor Application.compile_env(:appsignal, :appsignal_monitor, Appsignal.Monitor) @table :"$appsignal_registry" diff --git a/lib/appsignal/transmitter.ex b/lib/appsignal/transmitter.ex index 90e27401b..9b7fcb36d 100644 --- a/lib/appsignal/transmitter.ex +++ b/lib/appsignal/transmitter.ex @@ -1,7 +1,7 @@ defmodule Appsignal.Transmitter do @moduledoc false - import Appsignal.Utils, only: [warning: 1] + require Logger def request(method, url, headers \\ [], body \\ "") do http_client = Application.get_env(:appsignal, :http_client, :hackney) @@ -62,7 +62,7 @@ defmodule Appsignal.Transmitter do {:error, message} -> unless ca_file_path == packaged_ca_file_path() do - warning( + Logger.warning( "Ignoring non-existing or unreadable ca_file_path (#{ca_file_path}): #{inspect(message)}" ) end diff --git a/lib/appsignal/utils.ex b/lib/appsignal/utils.ex index 7d73b7230..4863bf128 100644 --- a/lib/appsignal/utils.ex +++ b/lib/appsignal/utils.ex @@ -1,8 +1,6 @@ defmodule Appsignal.Utils do @moduledoc false - require Logger - @doc """ Converts module name atoms to strings. @@ -21,23 +19,19 @@ defmodule Appsignal.Utils do def module_name(module), do: module |> to_string() |> module_name() - defdelegate info(message), to: Logger + def info(message) do + require Logger + Logger.info(message) + end - if Version.compare(System.version(), "1.11.0") == :lt do - defdelegate warning(message), to: Logger, as: :warn - else - defdelegate warning(message), to: Logger + def warning(message) do + require Logger + Logger.warning(message) end defmacro compile_env(app, key, default \\ nil) do - if Version.match?(System.version(), ">= 1.10.0") do - quote do - Application.compile_env(unquote(app), unquote(key), unquote(default)) - end - else - quote do - Application.get_env(unquote(app), unquote(key), unquote(default)) - end + quote do + Application.compile_env(unquote(app), unquote(key), unquote(default)) end end end diff --git a/lib/appsignal/utils/hostname.ex b/lib/appsignal/utils/hostname.ex index 0f441ae7d..afbf39e38 100644 --- a/lib/appsignal/utils/hostname.ex +++ b/lib/appsignal/utils/hostname.ex @@ -1,9 +1,7 @@ defmodule Appsignal.Utils.Hostname do @moduledoc false - require Appsignal.Utils - - @inet Appsignal.Utils.compile_env(:appsignal, :inet, :inet) + @inet Application.compile_env(:appsignal, :inet, :inet) def hostname do case Application.fetch_env(:appsignal, :config) do diff --git a/lib/mix/tasks/appsignal.diagnose.ex b/lib/mix/tasks/appsignal.diagnose.ex index d20a3154e..85149509a 100644 --- a/lib/mix/tasks/appsignal.diagnose.ex +++ b/lib/mix/tasks/appsignal.diagnose.ex @@ -3,10 +3,8 @@ defmodule Mix.Tasks.Appsignal.Diagnose do alias Appsignal.Config alias Appsignal.Diagnose - require Appsignal.Utils - - @system Appsignal.Utils.compile_env(:appsignal, :appsignal_system, Appsignal.System) - @report Appsignal.Utils.compile_env( + @system Application.compile_env(:appsignal, :appsignal_system, Appsignal.System) + @report Application.compile_env( :appsignal, :appsignal_diagnose_report, Appsignal.Diagnose.Report diff --git a/mix_helpers.exs b/mix_helpers.exs index 5008ba728..6e5def647 100644 --- a/mix_helpers.exs +++ b/mix_helpers.exs @@ -2,30 +2,14 @@ unless Code.ensure_loaded?(Appsignal.Agent) do {_, _} = Code.eval_file("agent.exs") end -defmodule Mix.Appsignal.Utils do - defmacro compile_env(app, key, default \\ nil) do - if Version.match?(System.version(), ">= 1.10.0") do - quote do - Application.compile_env(unquote(app), unquote(key), unquote(default)) - end - else - quote do - Application.get_env(unquote(app), unquote(key), unquote(default)) - end - end - end -end - defmodule Mix.Appsignal.Helper do @moduledoc """ Helper functions for downloading and compiling the AppSignal agent library. """ - require Mix.Appsignal.Utils - - @erlang Mix.Appsignal.Utils.compile_env(:appsignal, :erlang, :erlang) - @os Mix.Appsignal.Utils.compile_env(:appsignal, :os, :os) - @system Mix.Appsignal.Utils.compile_env(:appsignal, :mix_system, System) + @erlang Application.compile_env(:appsignal, :erlang, :erlang) + @os Application.compile_env(:appsignal, :os, :os) + @system Application.compile_env(:appsignal, :mix_system, System) @proxy_env_vars [ "APPSIGNAL_HTTP_PROXY",