View Source DBConnection.TelemetryListener (db_connection v2.7.0)

A connection listener that emits telemetry events for connection and disconnection

It monitors connection processes and ensures that disconnection events are always emitted.

Usage

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])

# Using a tag, which will be sent in telemetry metadata
{: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

Connected

[:db_connection, :connected] - Executed after a connection is established.

Measurements

  • :count - Always 1

Metadata

  • :pid - The connection pid
  • :tag - The connection pool tag

Disconnected

[:db_connection, :disconnected] - Executed after a disconnect.

Measurements

  • :count - Always 1

Metadata

  • :pid - The connection pid
  • :tag - The connection pool tag

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts a telemetry listener

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec start_link(GenServer.options()) :: {:ok, pid()}

Starts a telemetry listener