Skip to content

Commit 2b20ce7

Browse files
committed
Add docs for using telemetry listener with Ecto
1 parent 00cc69b commit 2b20ce7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/db_connection/telemetry_listener.ex

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,25 @@ defmodule DBConnection.TelemetryListener do
1010
Start the listener, and pass it under the `:connection_listeners` option when
1111
starting DBConnection:
1212
13-
{:ok, pid} = TelemetryListener.start_link()
13+
{:ok, pid} = DBConnection.TelemetryListener.start_link()
1414
{:ok, _conn} = DBConnection.start_link(SomeModule, connection_listeners: [pid])
1515
1616
# Using a tag, which will be sent in telemetry metadata
1717
{:ok, _conn} = DBConnection.start_link(SomeModule, connection_listeners: {[pid], :my_tag})
1818
1919
# Or, with a Supervisor:
2020
Supervisor.start_link([
21-
{TelemetryListener, [name: MyListener]},
21+
{DBConnection.TelemetryListener, name: MyListener},
2222
DBConnection.child_spec(SomeModule, connection_listeners: {[MyListener], :my_tag})
2323
])
2424
25+
When using with Ecto, you can pass the `connection_listeners` option to Ecto, and we
26+
recommend passing the repository as the tag. In your supervision tree:
27+
28+
Supervisor.start_link([
29+
{DBConnection.TelemetryListener, name: MyApp.DBListener},
30+
{MyApp.Repo, connection_listeners: {[MyApp.DBListener], MyApp.Repo})
31+
])
2532
2633
## Telemetry events
2734

0 commit comments

Comments
 (0)