spandex-project / spandex

A platform agnostic tracing library
MIT License
333 stars 53 forks source link

Modernize configuration #38

Closed zachdaniel closed 6 years ago

zachdaniel commented 6 years ago

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.

zachdaniel commented 6 years ago

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.

zachdaniel commented 6 years ago

Closed by #48. README is updated accordingly.