@@ -98,7 +98,7 @@ export const hack = <T extends typeof http.request>(
98
98
} ;
99
99
100
100
const { timestamps } = requestLog ;
101
- timestamps . requestStart = new Date ( ) ;
101
+ timestamps . requestStart = new Date ( ) . getTime ( ) ;
102
102
103
103
const clearDomain = ( ) : void => {
104
104
const parser = ( request . socket as any ) ?. parser as any ;
@@ -117,7 +117,7 @@ export const hack = <T extends typeof http.request>(
117
117
} ;
118
118
119
119
request . once ( "socket" , ( socket : Socket ) : void => {
120
- timestamps . onSocket = new Date ( ) ;
120
+ timestamps . onSocket = new Date ( ) . getTime ( ) ;
121
121
122
122
if ( ! isIP ( hostname ) ) {
123
123
socket . once ( "lookup" , (
@@ -126,9 +126,8 @@ export const hack = <T extends typeof http.request>(
126
126
family : string | number ,
127
127
host : string
128
128
) : void => {
129
- timestamps . onLookUp = new Date ( ) ;
130
- timestamps . dnsTime = timestamps . onLookUp . getTime ( )
131
- - timestamps . onSocket . getTime ( ) ;
129
+ timestamps . onLookUp = new Date ( ) . getTime ( ) ;
130
+ timestamps . dnsTime = timestamps . onLookUp - timestamps . onSocket ;
132
131
133
132
logger . debug ( `${ logPre } Dns lookup ${ host } -> ${
134
133
address || "null" } . Cost ${ timestamps . dnsTime } ms`) ;
@@ -146,12 +145,12 @@ export const hack = <T extends typeof http.request>(
146
145
}
147
146
148
147
socket . once ( "connect" , ( ) : void => {
149
- timestamps . socketConnect = new Date ( ) ;
148
+ timestamps . socketConnect = new Date ( ) . getTime ( ) ;
150
149
151
150
logger . debug ( `${ logPre } Socket connected. Remote: ${
152
151
socket . remoteAddress
153
152
} :${ socket . remotePort } . Cost ${
154
- timestamps . socketConnect . getTime ( ) - timestamps . onSocket . getTime ( )
153
+ timestamps . socketConnect - timestamps . onSocket
155
154
} ms`) ;
156
155
} ) ;
157
156
@@ -177,7 +176,7 @@ export const hack = <T extends typeof http.request>(
177
176
request . once ( "close" , clearDomain ) ;
178
177
179
178
request . once ( "finish" , ( ) => {
180
- timestamps . requestFinish = new Date ( ) ;
179
+ timestamps . requestFinish = new Date ( ) . getTime ( ) ;
181
180
182
181
context . captureSN += 1 ;
183
182
@@ -196,14 +195,14 @@ export const hack = <T extends typeof http.request>(
196
195
logger . debug ( `${ logPre } Request send finish. Body size ${
197
196
length
198
197
} . Cost: ${
199
- timestamps . requestFinish . getTime ( ) - timestamps . onSocket . getTime ( )
198
+ timestamps . requestFinish - timestamps . onSocket
200
199
} ms`) ;
201
200
202
201
clearDomain ( ) ;
203
202
} ) ;
204
203
205
204
request . once ( "response" , ( response : http . IncomingMessage ) : void => {
206
- timestamps . onResponse = new Date ( ) ;
205
+ timestamps . onResponse = new Date ( ) . getTime ( ) ;
207
206
208
207
const { socket } = response ;
209
208
requestLog . serverIp = socket . remoteAddress ;
@@ -220,15 +219,14 @@ export const hack = <T extends typeof http.request>(
220
219
} :${ socket . remotePort } . Response status code: ${
221
220
response . statusCode
222
221
} . Cost: ${
223
- timestamps . onResponse . getTime ( )
224
- - timestamps . onSocket . getTime ( )
222
+ timestamps . onResponse - timestamps . onSocket
225
223
} ms`) ;
226
224
227
225
// responseInfo can't retrieve data until response "end" event
228
226
const responseInfo = captureIncoming ( response ) ;
229
227
230
228
response . once ( "end" , ( ) => {
231
- timestamps . responseClose = new Date ( ) ;
229
+ timestamps . responseClose = new Date ( ) . getTime ( ) ;
232
230
233
231
requestLog . statusCode = response . statusCode ;
234
232
requestLog . responseLength = responseInfo . bodyLength ;
@@ -262,8 +260,7 @@ export const hack = <T extends typeof http.request>(
262
260
logger . debug ( `${ logPre } Response on end. Body size:${
263
261
requestLog . responseLength
264
262
} . Cost: ${
265
- timestamps . responseClose . getTime ( )
266
- - timestamps . onSocket . getTime ( )
263
+ timestamps . responseClose - timestamps . onSocket
267
264
} ms`) ;
268
265
269
266
finishRequest ( ) ;
0 commit comments