diesel-tracing
diesel-tracing copied to clipboard
Parse postgresql connection strings
In order to get more connection information for opentelemetry fields there are two possible approaches:
- Use the libpg C FFI to parse the connection string
- 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.