@@ -64,7 +64,7 @@ const Agent = require('_http_agent');
64
64
const { Buffer } = require ( 'buffer' ) ;
65
65
const { defaultTriggerAsyncIdScope } = require ( 'internal/async_hooks' ) ;
66
66
const { URL , urlToHttpOptions, searchParamsSymbol } = require ( 'internal/url' ) ;
67
- const { kOutHeaders, kNeedDrain, emitStatistics } = require ( 'internal/http' ) ;
67
+ const { kOutHeaders, kNeedDrain } = require ( 'internal/http' ) ;
68
68
const { connResetException, codes } = require ( 'internal/errors' ) ;
69
69
const {
70
70
ERR_HTTP_HEADERS_SENT ,
@@ -84,10 +84,10 @@ const {
84
84
85
85
const {
86
86
hasObserver,
87
+ startPerf,
88
+ stopPerf,
87
89
} = require ( 'internal/perf/observe' ) ;
88
90
89
- const { now } = require ( 'internal/perf/utils' ) ;
90
-
91
91
const kClientRequestStatistics = Symbol ( 'ClientRequestStatistics' ) ;
92
92
93
93
const { addAbortSignal, finished } = require ( 'stream' ) ;
@@ -355,10 +355,17 @@ ClientRequest.prototype._finish = function _finish() {
355
355
DTRACE_HTTP_CLIENT_REQUEST ( this , this . socket ) ;
356
356
FunctionPrototypeCall ( OutgoingMessage . prototype . _finish , this ) ;
357
357
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
+ } ) ;
362
369
}
363
370
} ;
364
371
@@ -627,7 +634,17 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
627
634
}
628
635
629
636
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
+ }
631
648
req . res = res ;
632
649
res . req = req ;
633
650
0 commit comments