spandex-project/spandex

Modernize configuration

zachdaniel opened this issue · 2 comments

We should follow modern patterns for configuration, and use a pattern whereby configuration is scoped to a module, such that there could be multiple, differently configured tracers.

The current plan is to provide an init callback, as well as a use statement to configure your own tracer. Per the recommendations here: https://michal.muskala.eu/2017/07/30/configuring-elixir-libraries.html, the functions in Spandex will all take their entire configuration as opts. Then an implementor of the library can use Spandex.Tracer, and override any functions they'd like to override.

# in config/config.exs

config :my_app, MyApp.Tracer,
  service: :my_app,
  adapter: MyAdapter

# in lib/tracer.ex

defmodule MyApp.Tracer do
  use Spandex.Tracer, otp_app: :my_app

  def init(config) do
    Keyword.put(config, :key, get_runtime_value())
  end
end

This just boils down to providing those opts to all of the Spandex module's functions without having to specify them all the time. This empowers the most use cases possible in my opinion.

Closed by #48. README is updated accordingly.