pgconn: support configuring the pgproto3 tracer before opening a connection #2457
+651
−50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
pgproto3tracer was only configurable after establishing a connection, which means that there were no means to trace the initial messages exchanged during the connection handshake.This PR adds two new fields to
pgconn.Config:TracerandTracerOptions, to support configuring the tracer earlier during the connection lifecycle, and have it trace the handshake messages.I also added methods to
TracerOptionsto support parsing the tracer messages. My intent is to use those parsing functions to reconstruct structured data from those messages. I took this approach to avoid making any breaking changes on inconsistencies, since theio.Writer-based API was already supported.Finally, I modified the internal tracer implementation a bit to minimize heap allocations, especially on paths that would allocate intermediary strings to format the tracer messages.
Let me know if you have any feedback.