diagnostics_channel: specialized tracing channels#62641
diagnostics_channel: specialized tracing channels#62641Qard wants to merge 1 commit intonodejs:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62641 +/- ##
==========================================
+ Coverage 89.72% 89.80% +0.08%
==========================================
Files 695 697 +2
Lines 214464 216293 +1829
Branches 41067 41405 +338
==========================================
+ Hits 192420 194251 +1831
- Misses 14106 14135 +29
+ Partials 7938 7907 -31
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
I'm having a bit of difficulty following these changes. I think having an example of usage for each of the methods will be very helpful.
There was a problem hiding this comment.
Yes, I'll get to documenting it better. The general idea is to split calls from continuations, and to split different forms of continuation from each other.
const syncChannel = dc.syncTracingChannel('test')
const callbackChannel = dc.callbackTracingChannel('test')
const promiseChannel = dc.promiseTracingChannel('test')
function callbackOrPromiseFn(cb) {
if (cb) return setImmediate(cb)
return new Promise(resolve => setImmediate(resolve))
}
// Wrap the sync portion of any call
const wrappedFoo = syncChannel.wrap(callbackOrPromiseFn, {
// Wrap the callback to produce asyncStart/asyncEnd, if present
wrapArgs(args) {
if (!args.length) return []
return [ callbackChannel.wrap(args[0]) ]
},
// Wrap the returned promise to produce asyncStart/asyncEnd, if present
mapOutcome(maybePromise) {
if (!Promise.isPromise(maybePromise)) return maybePromise
return promiseChannel.wrap(maybePromise)
}
})It's a bit more verbose than what we have now, but a lot more flexible to compose different patterns user code may do. We can also build the higher-level abstractions over top of this for the cases where simpler abstractions are viable.
There was a problem hiding this comment.
Thank you. That example is very helpful.
This is still a work-in-progress, but I want to share this before the collab summit so people can see the direction I'm trying to go with this and think about it for the upcoming session on these and other Observability changes I'm working on.
The general idea is that TracingChannel having sync, callback, and promise trace functions was a bit inflexible. What I'm going for here is to split apart concerns into three tracing categories: calls, parameter mapping for callbacks, and return value mapping for promises and iterators.
I'll continue working on this, and especially improving the docs to explain these concepts in more detail.
cc @nodejs/diagnostics