@@ -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,17 @@ 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+ headers : typeof this . getHeaders === 'function' ? this . getHeaders ( ) : { } ,
363+ } ,
364+ } ,
365+ } ) ;
359366 }
360367} ;
361368
@@ -624,7 +631,17 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
624631 }
625632
626633 DTRACE_HTTP_CLIENT_RESPONSE ( socket , req ) ;
627- emitStatistics ( req [ kClientRequestStatistics ] ) ;
634+ if ( req [ kClientRequestStatistics ] && hasObserver ( 'http' ) ) {
635+ stopPerf ( req , kClientRequestStatistics , {
636+ detail : {
637+ res : {
638+ statusCode : res . statusCode ,
639+ statusMessage : res . statusMessage ,
640+ headers : res . headers ,
641+ } ,
642+ } ,
643+ } ) ;
644+ }
628645 req . res = res ;
629646 res . req = req ;
630647
0 commit comments