How should I configure my supervised library?

I have read the guidelines on creating a library and am uncertain how best to pass opts and configure my library. I have also looked at Ecto, Broadway, and the generated Telemetry supervisor in a Phoenix app as references.

  • I have a standalone Elixir library (1.14.0 / OTP 25) - Foo
  • It has a supervision tree created with mix new foo --sup
  • Foo.Application adds children for a registry and a dynamic supervisor
  • Foo.MixProject has mod: {Foo.Application, []}


  1. Application.get_env not recommended
  2. have a module in the parent with a use or @behavior into the lib

Say in the parent app:

defmodule Bar.Foo do
  use Foo # or @behaviour Foo

aside: use vs behavior
I don’t care which really is used; the library documentation can have a code snippet to paste into a parent for start_link and child_spec, or those can be already implemented in the macro.

Questions / thoughts:

  1. If Bar.Foo is added to the parent apps supervision tree I can add config options
  2. Do I keep the mod: {Foo.Application, []} or remove it and let Bar.Foo handle the setup?
  3. But what about the Foo.Application supervision setup?
  4. Can I reuse that somehow?
  5. Is there an easier way to do this?


1 Like