diesel-tracing icon indicating copy to clipboard operation
diesel-tracing copied to clipboard

Parse postgresql connection strings

Open johnchildren opened this issue 3 years ago • 0 comments

In order to get more connection information for opentelemetry fields there are two possible approaches:

  1. Use the libpg C FFI to parse the connection string
  2. Implement a custom mini parser

Unfortunately diesel does not expose the bindings to libpg to users, so we are forced to go with option 2 I think. Having a separate FFI to libpg seems like a quite bad idea in terms of future API compatibility.

https://www.postgresql.org/docs/10/libpq-connect.html#LIBPQ-CONNSTRING

We can also populate the host and port number from the connection string this way, which would resolve both:

  • https://github.com/CQCL/diesel-tracing/issues/12
  • https://github.com/CQCL/diesel-tracing/issues/9

Importantly the structure returned should not include any passwords in the connection string.

If the parsing fails we should log the error but continue as we cannot change the interface of connecting and the connection might succeed anyway.

johnchildren avatar Oct 21 '20 08:10 johnchildren