I have a question/suggestion for the longer-term:
Is it possible to refactor & use the Promise API for chaining asynchronous events? - I think it should solve the issue of deeply nested contexts.
[2020-02-01T01:43:31.710Z]DEBUG (20) (@slonik):created a new client connectionpoolId:01DZZ6NN2S2P4TD0CM8YJZKPK3processId:77955stats:idleConnectionCount:0totalConnectionCount:3waitingRequestCount:0[2020-02-01T01:43:31.710Z]DEBUG (20) (@slonik):client is checked out from the poolpoolId:01DZZ6NN2S2P4TD0CM8YJZKPK3processId:77955stats:idleConnectionCount:0totalConnectionCount:3waitingRequestCount:0[2020-02-01T01:43:31.712Z]DEBUG (20) (@slonik):created a new client connectionpoolId:01DZZ6NN2S2P4TD0CM8YJZKPK3processId:77953stats:idleConnectionCount:0totalConnectionCount:3waitingRequestCount:0[2020-02-01T01:43:31.712Z]DEBUG (20) (@slonik):client is checked out from the poolpoolId:01DZZ6NN2S2P4TD0CM8YJZKPK3processId:77953stats:idleConnectionCount:0totalConnectionCount:3waitingRequestCount:0[2020-02-01T01:43:31.712Z]DEBUG (20) (@slonik):created a new client connectionpoolId:01DZZ6NN2S2P4TD0CM8YJZKPK3processId:77954stats:idleConnectionCount:0totalConnectionCount:3waitingRequestCount:0[2020-02-01T01:43:31.712Z]DEBUG (20) (@slonik):client is checked out from the poolpoolId:01DZZ6NN2S2P4TD0CM8YJZKPK3processId:77954stats:idleConnectionCount:0totalConnectionCount:3waitingRequestCount:0[2020-02-01T01:43:36.725Z]DEBUG (20) (@slonik):client connection is closed and removed from the client poolpoolId:01DZZ6NN2S2P4TD0CM8YJZKPK3processId:77955stats:idleConnectionCount:2totalConnectionCount:2waitingRequestCount:0[2020-02-01T01:43:36.725Z]DEBUG (20) (@slonik):client connection is closed and removed from the client poolpoolId:01DZZ6NN2S2P4TD0CM8YJZKPK3processId:77954stats:idleConnectionCount:1totalConnectionCount:1waitingRequestCount:0[2020-02-01T01:43:36.726Z]DEBUG (20) (@slonik):client connection is closed and removed from the client poolpoolId:01DZZ6NN2S2P4TD0CM8YJZKPK3processId:77953stats:idleConnectionCount:0totalConnectionCount:0waitingRequestCount:0
If there was an issue with one of the query executions, the above logs would not be particularly useful, and there is no way to pass additional details to the logger.
The only change we did was wrap updatePost body in Roarr.adopt and now the logs contain meaningful context information (the postId):
[2020-02-01T01:49:41.046Z]DEBUG (20) (@slonik):created a new client connectionpostId:2poolId:01DZZ70XRJDS3W02FR36JZEJK5processId:78010stats:idleConnectionCount:0totalConnectionCount:3waitingRequestCount:0[2020-02-01T01:49:41.046Z]DEBUG (20) (@slonik):client is checked out from the poolpostId:2poolId:01DZZ70XRJDS3W02FR36JZEJK5processId:78010stats:idleConnectionCount:0totalConnectionCount:3waitingRequestCount:0[2020-02-01T01:49:41.048Z]DEBUG (20) (@slonik):created a new client connectionpostId:1poolId:01DZZ70XRJDS3W02FR36JZEJK5processId:78011stats:idleConnectionCount:0totalConnectionCount:3waitingRequestCount:0[2020-02-01T01:49:41.048Z]DEBUG (20) (@slonik):client is checked out from the poolpostId:1poolId:01DZZ70XRJDS3W02FR36JZEJK5processId:78011stats:idleConnectionCount:0totalConnectionCount:3waitingRequestCount:0[2020-02-01T01:49:41.048Z]DEBUG (20) (@slonik):created a new client connectionpostId:3poolId:01DZZ70XRJDS3W02FR36JZEJK5processId:78012stats:idleConnectionCount:0totalConnectionCount:3waitingRequestCount:0[2020-02-01T01:49:41.049Z]DEBUG (20) (@slonik):client is checked out from the poolpostId:3poolId:01DZZ70XRJDS3W02FR36JZEJK5processId:78012stats:idleConnectionCount:0totalConnectionCount:3waitingRequestCount:0[2020-02-01T01:49:46.065Z]DEBUG (20) (@slonik):client connection is closed and removed from the client poolpostId:2poolId:01DZZ70XRJDS3W02FR36JZEJK5processId:78010stats:idleConnectionCount:2totalConnectionCount:2waitingRequestCount:0[2020-02-01T01:49:46.067Z]DEBUG (20) (@slonik):client connection is closed and removed from the client poolpostId:1poolId:01DZZ70XRJDS3W02FR36JZEJK5processId:78011stats:idleConnectionCount:1totalConnectionCount:1waitingRequestCount:0[2020-02-01T01:49:46.068Z]DEBUG (20) (@slonik):client connection is closed and removed from the client poolpostId:3poolId:01DZZ70XRJDS3W02FR36JZEJK5processId:78012stats:idleConnectionCount:0totalConnectionCount:0waitingRequestCount:0
In a real-world scenario, Roarr.adopt would wrap large parts of your codebase whenever there is additional context information that needs to be added to the logs of descended operations. The added context information will appear with all the logs regardless of however deep in your code those asynchronous calls are made.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Insightful 🎊
I have a question/suggestion for the longer-term:
Is it possible to refactor & use the Promise API for chaining asynchronous events? - I think it should solve the issue of deeply nested contexts.
@gajus thoughts?
The problem that Domains solve is inheritance from any asynchronous context, e.g.
Suppose that your application uses Slonik to run PostgreSQL queries, and you have
updatePost
function that is run concurrently:The above program would produce logs:
If there was an issue with one of the query executions, the above logs would not be particularly useful, and there is no way to pass additional details to the logger.
Let's add
Roarr.adopt
:The only change we did was wrap
updatePost
body inRoarr.adopt
and now the logs contain meaningful context information (thepostId
):In a real-world scenario,
Roarr.adopt
would wrap large parts of your codebase whenever there is additional context information that needs to be added to the logs of descended operations. The added context information will appear with all the logs regardless of however deep in your code those asynchronous calls are made.