defmodule PerfAgent do @moduledoc """ Entry point for Perf Agent """ use Application @doc """ Application callback to start Perf Agent """ @spec start(Application.app, Application.start_type) :: :ok | {:error, term} def start(_type \\ :normal, _args \\ []) do import Supervisor.Spec, warn: false children = [] opts = [strategy: :one_for_one, name: PerfAgent.Supervisor] result = Supervisor.start_link(children, opts) if api_key = Application.get_env(:perf_agent, :api_key) do # Queue is the shared agent between the recorder and the poller {:ok, queue} = PerfAgent.TransactionQueue.start_link() {:ok, _} = PerfAgent.Poller.start_link(queue) {:ok, recorder} = PerfAgent.Recorder.start_link(queue) # Put recorder in application config to access from plug Application.put_env(:perf_agent, :recorder, recorder) end result end @doc """ Checks if the required configuration params are set. Application will take no action if not set. """ @spec configured? :: boolean def configured? do Application.get_env(:perf_agent, :api_key) != nil end end