@@ -61,7 +61,7 @@ const Agent = require('_http_agent');
6161const { Buffer } = require ( 'buffer' ) ;
6262const { defaultTriggerAsyncIdScope } = require ( 'internal/async_hooks' ) ;
6363const { URL , urlToHttpOptions, searchParamsSymbol } = require ( 'internal/url' ) ;
64- const { kOutHeaders, kNeedDrain, emitStatistics } = require ( 'internal/http' ) ;
64+ const { kOutHeaders, kNeedDrain } = require ( 'internal/http' ) ;
6565const { connResetException, codes } = require ( 'internal/errors' ) ;
6666const {
6767 ERR_HTTP_HEADERS_SENT ,
@@ -81,10 +81,10 @@ const {
8181
8282const {
8383 hasObserver,
84+ startPerf,
85+ stopPerf,
8486} = require ( 'internal/perf/observe' ) ;
8587
86- const { now } = require ( 'internal/perf/utils' ) ;
87-
8888const kClientRequestStatistics = Symbol ( 'ClientRequestStatistics' ) ;
8989
9090const { addAbortSignal, finished } = require ( 'stream' ) ;
@@ -352,10 +352,16 @@ ClientRequest.prototype._finish = function _finish() {
352352 DTRACE_HTTP_CLIENT_REQUEST ( this , this . socket ) ;
353353 FunctionPrototypeCall ( OutgoingMessage . prototype . _finish , this ) ;
354354 if ( hasObserver ( 'http' ) ) {
355- this [ kClientRequestStatistics ] = {
356- startTime : now ( ) ,
357- type : 'HttpClient' ,
358- } ;
355+ startPerf ( this , kClientRequestStatistics , {
356+ type : 'http' ,
357+ name : 'HttpClient' ,
358+ detail : {
359+ req : {
360+ method : this . method ,
361+ url : `${ this . protocol } //${ this . host } ${ this . path } ` ,
362+ } ,
363+ } ,
364+ } ) ;
359365 }
360366} ;
361367
@@ -624,7 +630,17 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
624630 }
625631
626632 DTRACE_HTTP_CLIENT_RESPONSE ( socket , req ) ;
627- emitStatistics ( req [ kClientRequestStatistics ] ) ;
633+ if ( req [ kClientRequestStatistics ] && hasObserver ( 'http' ) ) {
634+ stopPerf ( req , kClientRequestStatistics , {
635+ detail : {
636+ res : {
637+ statusCode : res . statusCode ,
638+ statusMessage : res . statusMessage ,
639+ headers : res . headers ,
640+ } ,
641+ } ,
642+ } ) ;
643+ }
628644 req . res = res ;
629645 res . req = req ;
630646
0 commit comments