Thanks to the discussion in this thread, I ended up doing something like this:
def handle_event(
[:my_app, :repo :query],
_measurements,
%{result: {:error, error}, query: query},
_config
) do
# Log the query
end
That will capture more than just timeouts. If that’s a problem then you can go through the additional work to match on error
or add some other filtering so that you only get timeouts. In my experience testing locally I saw a few different errors associated with timeouts but in production so far we’ve only seen this one:
Postgrex.Protocol (#PID<0.18044.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.18926.0> timed out because it queued and checked out the connection for longer than 5ms