MCPcopy Create free account
hub / github.com/nodejs/node / diagnostics_channel

Function diagnostics_channel

benchmark/diagnostics_channel/http.js:67–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65}
66
67function diagnostics_channel() {
68 const als = new AsyncLocalStorage();
69 const times = [];
70
71 const start = dc.channel('http.server.request.start');
72 const finish = dc.channel('http.server.response.finish');
73
74 function onStart(req) {
75 als.enterWith({
76 url: req.url,
77 start: process.hrtime.bigint(),
78 });
79 }
80
81 function onFinish(res) {
82 times.push({
83 ...als.getStore(),
84 statusCode: res.statusCode,
85 end: process.hrtime.bigint(),
86 });
87 }
88
89 start.subscribe(onStart);
90 finish.subscribe(onFinish);
91
92 return () => {
93 start.unsubscribe(onStart);
94 finish.unsubscribe(onFinish);
95 };
96}

Callers

nothing calls this directly

Calls 2

subscribeMethod · 0.45
unsubscribeMethod · 0.45

Tested by

no test coverage detected