@@ -57,7 +57,7 @@ const Agent = require('_http_agent');
57
57
const { Buffer } = require ( 'buffer' ) ;
58
58
const { defaultTriggerAsyncIdScope } = require ( 'internal/async_hooks' ) ;
59
59
const { URL , urlToHttpOptions, searchParamsSymbol } = require ( 'internal/url' ) ;
60
- const { kOutHeaders, kNeedDrain } = require ( 'internal/http' ) ;
60
+ const { kOutHeaders, kNeedDrain, emitStatistics } = require ( 'internal/http' ) ;
61
61
const { connResetException, codes } = require ( 'internal/errors' ) ;
62
62
const {
63
63
ERR_HTTP_HEADERS_SENT ,
@@ -75,6 +75,12 @@ const {
75
75
DTRACE_HTTP_CLIENT_RESPONSE
76
76
} = require ( 'internal/dtrace' ) ;
77
77
78
+ const {
79
+ hasObserver,
80
+ } = require ( 'internal/perf/observe' ) ;
81
+
82
+ const kClientRequestStatistics = Symbol ( 'ClientRequestStatistics' ) ;
83
+
78
84
const { addAbortSignal, finished } = require ( 'stream' ) ;
79
85
80
86
let debug = require ( 'internal/util/debuglog' ) . debuglog ( 'http' , ( fn ) => {
@@ -337,6 +343,12 @@ ObjectSetPrototypeOf(ClientRequest, OutgoingMessage);
337
343
ClientRequest . prototype . _finish = function _finish ( ) {
338
344
DTRACE_HTTP_CLIENT_REQUEST ( this , this . socket ) ;
339
345
FunctionPrototypeCall ( OutgoingMessage . prototype . _finish , this ) ;
346
+ if ( hasObserver ( 'http' ) ) {
347
+ this [ kClientRequestStatistics ] = {
348
+ startTime : process . hrtime ( ) ,
349
+ type : 'HttpClient'
350
+ } ;
351
+ }
340
352
} ;
341
353
342
354
ClientRequest . prototype . _implicitHeader = function _implicitHeader ( ) {
@@ -604,6 +616,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
604
616
}
605
617
606
618
DTRACE_HTTP_CLIENT_RESPONSE ( socket , req ) ;
619
+ emitStatistics ( req [ kClientRequestStatistics ] ) ;
607
620
req . res = res ;
608
621
res . req = req ;
609
622
0 commit comments