You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above example will log the executing query by attaching a common ID used for the all logs in the current request. BTW easily we can track all the steps happened in a particular request. `
Only the place I am not able to track the raise notice logging from the db using correlationID is this place, The reason for it is I didn't get a way to access the current request context that we are passing in every query from pgconn.PgConn.
Config.ConnConfig.OnNotice = func(pc *pgconn.PgConn, n *pgconn.Notice) {
log := logger.GetFromCtx(context.Background()) // doing this
// log := logger.GetFromCtx(ctx) // want to do this
log.Trace().
Uint32("pid", pc.PID()).
Str("message", n.Message).
Str("severity", n.Severity).
Msg("Database notice")
}
The text was updated successfully, but these errors were encountered:
anazcodes
changed the title
Failed to trace the logs from DB via Raise Notice. Couldn't find a way to access current request context from Config.ConnConfig.OnNotice.
Failed to trace the logs from DB via Raise Notice. Couldn't find a way to access current request context from Config.ConnConfig.OnNotice.
Sep 13, 2024
jackc
changed the title
Failed to trace the logs from DB via Raise Notice. Couldn't find a way to access current request context from Config.ConnConfig.OnNotice.
Access current request context from Config.ConnConfig.OnNoticeSep 13, 2024
This might be possible, but it also could be difficult and a significant change.
A notice could be received at any time. Not just while receiving query results. In addition, the notice may not have any connection to a query that happened to be executing at that time.
That's why it does not include a ctx now. However, it should be possible to store a currentCtx on *pgconn.PgConn`. This would have to be set and cleared by every method that potentially could receive a notice while it was executing.
I'm not opposed to this change, but it may be a fair amount of work, and it's not something I will get to anytime soon.
Failed to get
context.Context
fromConfig.ConnConfig.OnNotice
I have implemented log tracing mechanism using a correlationID and I am accessing it everywhere to relate the logs.
Example
Only the place I am not able to track the raise notice logging from the db using correlationID is this place, The reason for it is I didn't get a way to access the current request context that we are passing in every query from pgconn.PgConn.
@jackc
The text was updated successfully, but these errors were encountered: