Finding a diameter socket

I often find myself needing to know the inet:socket() used in a diameter transport. For example if I specify the port as 0 so that an available port is assigned, which we often do for client connections, I may need to know which port was ultimately assigned. Also I may need to inspect the socket options or stats during operation.

Unfortunately this turns out to require using an undocumented and cumbersome API:

[#{ref := TransportRef}] = diameter:which_transports(Service),
[{{_, _, {_, {_, Socket}}}, _}] = diameter_reg:match({'_', '_', {TransportRef, '_'}}),
{ok, Port} = inet:port(Socket).

I wonder if anyone has a suggestion on what an API to do this would look like as I’m considering implementing something and sending a pull request.