@@ -64,7 +64,7 @@ const Agent = require('_http_agent');
6464const { Buffer } = require ( 'buffer' ) ;
6565const { defaultTriggerAsyncIdScope } = require ( 'internal/async_hooks' ) ;
6666const { URL , urlToHttpOptions, searchParamsSymbol } = require ( 'internal/url' ) ;
67- const { kOutHeaders, kNeedDrain, emitStatistics } = require ( 'internal/http' ) ;
67+ const { kOutHeaders, kNeedDrain } = require ( 'internal/http' ) ;
6868const { connResetException, codes } = require ( 'internal/errors' ) ;
6969const {
7070 ERR_HTTP_HEADERS_SENT ,
@@ -84,10 +84,10 @@ const {
8484
8585const {
8686 hasObserver,
87+ startPerf,
88+ stopPerf,
8789} = require ( 'internal/perf/observe' ) ;
8890
89- const { now } = require ( 'internal/perf/utils' ) ;
90-
9191const kClientRequestStatistics = Symbol ( 'ClientRequestStatistics' ) ;
9292
9393const { addAbortSignal, finished } = require ( 'stream' ) ;
@@ -355,10 +355,17 @@ ClientRequest.prototype._finish = function _finish() {
355355 DTRACE_HTTP_CLIENT_REQUEST ( this , this . socket ) ;
356356 FunctionPrototypeCall ( OutgoingMessage . prototype . _finish , this ) ;
357357 if ( hasObserver ( 'http' ) ) {
358- this [ kClientRequestStatistics ] = {
359- startTime : now ( ) ,
360- type : 'HttpClient' ,
361- } ;
358+ startPerf ( this , kClientRequestStatistics , {
359+ type : 'http' ,
360+ name : 'HttpClient' ,
361+ detail : {
362+ req : {
363+ method : this . method ,
364+ url : `${ this . protocol } //${ this . host } ${ this . path } ` ,
365+ headers : typeof this . getHeaders === 'function' ? this . getHeaders ( ) : { } ,
366+ } ,
367+ } ,
368+ } ) ;
362369 }
363370} ;
364371
@@ -627,7 +634,17 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
627634 }
628635
629636 DTRACE_HTTP_CLIENT_RESPONSE ( socket , req ) ;
630- emitStatistics ( req [ kClientRequestStatistics ] ) ;
637+ if ( req [ kClientRequestStatistics ] && hasObserver ( 'http' ) ) {
638+ stopPerf ( req , kClientRequestStatistics , {
639+ detail : {
640+ res : {
641+ statusCode : res . statusCode ,
642+ statusMessage : res . statusMessage ,
643+ headers : res . headers ,
644+ } ,
645+ } ,
646+ } ) ;
647+ }
631648 req . res = res ;
632649 res . req = req ;
633650
0 commit comments