Expose SeverityUnlocalized in Notice
mitar opened this issue · comments
Is your feature request related to a problem? Please describe.
I want to log Notice
s as I get them from the server. Currently they are exposed in Notice
struct, but that struct's Severity
field comes from localized S
field of the PotgreSQL notice message and not V
field. This makes is tricky to map severity to log levels.
Describe the solution you'd like
I think ErrorResponseToPgError
should just use SeverityUnlocalized
instead of Severity
if it is set. I cannot imagine localized field is really something people use.
Describe alternatives you've considered
I would have to figure out how can severity values be localized and invert that localization.
Additional context
I do not understand fully why OnNotice
gets PgError
and not directly ErrorResponse
. ErrorResponse
has also some nice features like JSON marshal which would be useful for logging. (BTW, ErrorResponse
's MarshalJSON
does not use idiomatic JSON field name casing. :-( )
I also do not get what exactly I can obtain from PgConn
. Documentation says "origin of the notice", but what exactly metadata is available on PgConn
to get this origin? It looks pretty opaque struct to me? I do not think I could attach some additional metadata to it in BeforeAcquire
?
I also do not get what exactly I can obtain from
PgConn
. Documentation says "origin of the notice", but what exactly metadata is available onPgConn
to get this origin? It looks pretty opaque struct to me? I do not think I could attach some additional metadata to it inBeforeAcquire
?
Oh, I can use conn.ParameterStatus("application_name")
to obtain application name. Awesome!
I've added SeverityUnlocalized
in a3d9120.
I think ErrorResponseToPgError should just use SeverityUnlocalized instead of Severity if it is set. I cannot imagine localized field is really something people use.
The V
field was not previously available. It was only added in PostgreSQL 9.6 which was released in 2016. pgx predates that (and also needed to support 9.5 until 2021).
I do not understand fully why OnNotice gets PgError and not directly ErrorResponse.
As a general design goal I try to avoid the implementation details of the wire protocol from leaking to the higher level layers (not always possible, but usually is). And on a concrete basis, pgproto3.ErrorResponse
used to use []byte
s that pointed directly to the shared network read buffer for its text fields. So a copy had to be made and a string
is much more convenient for the application developer.
Oh, I can use conn.ParameterStatus("application_name") to obtain application name. Awesome!
You can also get the PID of the connection with conn.PID()
.
Awesome, thanks!
You can also get the PID of the connection with conn.PID().
That to me looks less useful because I would have to maintain some weak map between PID and my own data?
You can also get the PID of the connection with conn.PID().
That to me looks less useful because I would have to maintain some weak map between PID and my own data?
I think #1896 would be a perfect solution for this. However, I proposed the idea over a month ago and no one has commented or even thumbs up or thumbs down. 🤷
Oh, that is exactly what I wanted. I was looking for where I could put some data. Currently I encode it into application name, but that would be better. I will comment there.