diff --git a/lib/db_connection.ex b/lib/db_connection.ex index ec343f3..188ec48 100644 --- a/lib/db_connection.ex +++ b/lib/db_connection.ex @@ -566,6 +566,8 @@ defmodule DBConnection do * `:opts` - All options given to the pool operation + See `DBConnection.TelemetryListener` for enabling `[:db_connection, :connected]` + and `[:db_connection, :disconnected]` events. """ @spec start_link(module, [start_option()] | Keyword.t()) :: GenServer.on_start() def start_link(conn_mod, opts) do diff --git a/lib/db_connection/telemetry_listener.ex b/lib/db_connection/telemetry_listener.ex index 66f4e40..5e1f16e 100644 --- a/lib/db_connection/telemetry_listener.ex +++ b/lib/db_connection/telemetry_listener.ex @@ -7,13 +7,21 @@ defmodule DBConnection.TelemetryListener do ## Usage - Start the listener, optionally using a name, and pass it under the - `:connection_listeners` option when starting DbConnection: + Start the listener, and pass it under the `:connection_listeners` option when + starting DBConnection: + + {:ok, pid} = TelemetryListener.start_link() + {:ok, _conn} = DBConnection.start_link(SomeModule, connection_listeners: [pid]) - {:ok, pid} = TelemetryListener.start_link([name: MyListener]) - {:ok, _conn} = DBConnection.start_link(SomeModule, [connection_listeners: [MyListener]]) # Using a tag, which will be sent in telemetry metadata - {:ok, _conn} = DBConnection.start_link(SomeModule, [connection_listeners: {[pid], :my_tag}]) + {:ok, _conn} = DBConnection.start_link(SomeModule, connection_listeners: {[pid], :my_tag}) + + # Or, with a Supervisor: + Supervisor.start_link([ + {TelemetryListener, [name: MyListener]}, + DBConnection.child_spec(SomeModule, connection_listeners: {[MyListener], :my_tag}) + ]) + ## Telemetry events