From 09ae2de4ebb7471d616b3407d507400005f605b1 Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Mon, 1 Jul 2024 11:33:40 -0300 Subject: [PATCH] Documentation improvements --- lib/db_connection.ex | 2 ++ lib/db_connection/telemetry_listener.ex | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) 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