@@ -64,7 +64,14 @@ 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 } = require ( 'internal/http' ) ;
67
+ const {
68
+ kOutHeaders,
69
+ kNeedDrain,
70
+ isTraceHTTPEnabled,
71
+ traceBegin,
72
+ traceEnd,
73
+ getNextTraceEventId,
74
+ } = require ( 'internal/http' ) ;
68
75
const { connResetException, codes } = require ( 'internal/errors' ) ;
69
76
const {
70
77
ERR_HTTP_HEADERS_SENT ,
@@ -106,6 +113,8 @@ const kError = Symbol('kError');
106
113
const kLenientAll = HTTPParser . kLenientAll | 0 ;
107
114
const kLenientNone = HTTPParser . kLenientNone | 0 ;
108
115
116
+ const HTTP_CLIENT_TRACE_EVENT_NAME = 'http.client.request' ;
117
+
109
118
function validateHost ( host , name ) {
110
119
if ( host !== null && host !== undefined && typeof host !== 'string' ) {
111
120
throw new ERR_INVALID_ARG_TYPE ( `options.${ name } ` ,
@@ -376,6 +385,10 @@ ClientRequest.prototype._finish = function _finish() {
376
385
request : this ,
377
386
} ) ;
378
387
}
388
+ if ( isTraceHTTPEnabled ( ) ) {
389
+ this . _traceEventId = getNextTraceEventId ( ) ;
390
+ traceBegin ( HTTP_CLIENT_TRACE_EVENT_NAME , this . _traceEventId ) ;
391
+ }
379
392
} ;
380
393
381
394
ClientRequest . prototype . _implicitHeader = function _implicitHeader ( ) {
@@ -660,6 +673,12 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
660
673
response : res ,
661
674
} ) ;
662
675
}
676
+ if ( isTraceHTTPEnabled ( ) && typeof req . _traceEventId === 'number' ) {
677
+ traceEnd ( HTTP_CLIENT_TRACE_EVENT_NAME , req . _traceEventId , {
678
+ path : req . path ,
679
+ statusCode : res . statusCode ,
680
+ } ) ;
681
+ }
663
682
req . res = res ;
664
683
res . req = req ;
665
684
0 commit comments