Skip to content

Commit 66b9ae9

Browse files
committed
http: trace http client by perf_hooks
1 parent a01302b commit 66b9ae9

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/_http_client.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ const {
7575
DTRACE_HTTP_CLIENT_RESPONSE
7676
} = require('internal/dtrace');
7777

78+
const {
79+
hasObserver,
80+
} = require('internal/perf/observe');
81+
82+
const {
83+
emitStatistics
84+
} = require('internal/http');
85+
86+
const kClientRequestStatistics = Symbol('ClientRequestStatistics');
87+
7888
const { addAbortSignal, finished } = require('stream');
7989

8090
let debug = require('internal/util/debuglog').debuglog('http', (fn) => {
@@ -337,6 +347,12 @@ ObjectSetPrototypeOf(ClientRequest, OutgoingMessage);
337347
ClientRequest.prototype._finish = function _finish() {
338348
DTRACE_HTTP_CLIENT_REQUEST(this, this.socket);
339349
FunctionPrototypeCall(OutgoingMessage.prototype._finish, this);
350+
if (hasObserver('http')) {
351+
this[kClientRequestStatistics] = {
352+
startTime: process.hrtime(),
353+
type: 'HttpClient'
354+
};
355+
}
340356
};
341357

342358
ClientRequest.prototype._implicitHeader = function _implicitHeader() {
@@ -604,6 +620,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
604620
}
605621

606622
DTRACE_HTTP_CLIENT_RESPONSE(socket, req);
623+
emitStatistics(req[kClientRequestStatistics]);
607624
req.res = res;
608625
res.req = req;
609626

lib/_http_server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ function ServerResponse(req) {
193193

194194
if (hasObserver('http')) {
195195
this[kServerResponseStatistics] = {
196-
startTime: process.hrtime()
196+
startTime: process.hrtime(),
197+
type: 'HttpRequest'
197198
};
198199
}
199200
}

lib/internal/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function emitStatistics(statistics) {
3838
const startTime = statistics.startTime;
3939
const diff = process.hrtime(startTime);
4040
const entry = new InternalPerformanceEntry(
41-
'HttpRequest',
41+
statistics.type,
4242
'http',
4343
startTime[0] * 1000 + startTime[1] / 1e6,
4444
diff[0] * 1000 + diff[1] / 1e6,

0 commit comments

Comments
 (0)