Skip to content

Commit

Permalink
Remove Appsignal.Utils.compile_env/3
Browse files Browse the repository at this point in the history
In the process of dropping Elixir versions before 1.11, remove
Appsignal.Utils.compile_env/3, which was added to switch between
Application.compile_env/3 and Application.get_env/3.

[skip changeset]
  • Loading branch information
jeffkreeftmeijer committed Jun 26, 2024
1 parent c065f44 commit 024a379
Show file tree
Hide file tree
Showing 24 changed files with 34 additions and 82 deletions.
5 changes: 2 additions & 3 deletions lib/appsignal/absinthe.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
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

Expand Down
4 changes: 1 addition & 3 deletions lib/appsignal/demo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
4 changes: 1 addition & 3 deletions lib/appsignal/diagnose/agent.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 2 additions & 4 deletions lib/appsignal/diagnose/host.ex
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 1 addition & 3 deletions lib/appsignal/diagnose/library.ex
Original file line number Diff line number Diff line change
@@ -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
%{
Expand Down
5 changes: 2 additions & 3 deletions lib/appsignal/ecto.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
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)
@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 """
Expand Down
3 changes: 1 addition & 2 deletions lib/appsignal/ecto_repo.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/appsignal/error/backend.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
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

Expand Down
5 changes: 2 additions & 3 deletions lib/appsignal/finch.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
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

Expand Down
3 changes: 1 addition & 2 deletions lib/appsignal/heartbeat.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 2 additions & 4 deletions lib/appsignal/instrumentation.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/appsignal/instrumentation/decorators.ex
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 2 additions & 4 deletions lib/appsignal/integration_logger.ex
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
4 changes: 1 addition & 3 deletions lib/appsignal/logger.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 2 additions & 4 deletions lib/appsignal/monitor.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 3 additions & 4 deletions lib/appsignal/oban.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
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

Expand Down
1 change: 0 additions & 1 deletion lib/appsignal/probes/erlang_probe.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule Appsignal.Probes.ErlangProbe do
@moduledoc false
require Appsignal.Utils

def call(sample \\ nil) do
next_sample = sample_schedulers()
Expand Down
3 changes: 1 addition & 2 deletions lib/appsignal/probes/probes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/appsignal/span.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
5 changes: 2 additions & 3 deletions lib/appsignal/tesla.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
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

Expand Down
4 changes: 1 addition & 3 deletions lib/appsignal/tracer.ex
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
12 changes: 0 additions & 12 deletions lib/appsignal/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,4 @@ defmodule Appsignal.Utils 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
end
end
end
4 changes: 1 addition & 3 deletions lib/appsignal/utils/hostname.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 2 additions & 4 deletions lib/mix/tasks/appsignal.diagnose.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 024a379

Please sign in to comment.