@@ -10,6 +10,7 @@ const localize = nls.loadMessageBundle()
10
10
11
11
import * as AWS from 'aws-sdk'
12
12
import * as logger from '../logger/logger'
13
+ import { PerfLog } from '../logger/logger'
13
14
import { ServiceConfigurationOptions } from 'aws-sdk/lib/service'
14
15
import { CancellationError , Timeout , waitTimeout , waitUntil } from '../utilities/timeoutUtils'
15
16
import { isUserCancelledError } from '../../shared/errors'
@@ -28,8 +29,8 @@ import {
28
29
ListSourceRepositoriesItem ,
29
30
ListSourceRepositoriesItems ,
30
31
} from 'aws-sdk/clients/codecatalyst'
32
+ import { truncateProps } from '../utilities/textUtilities'
31
33
32
- // REMOVE ME SOON: only used for development
33
34
interface CodeCatalystConfig {
34
35
readonly region : string
35
36
readonly endpoint : string
@@ -224,10 +225,12 @@ class CodeCatalystClientInternal {
224
225
const log = this . log
225
226
const bearerToken = ( await this . connection . getToken ( ) ) . accessToken
226
227
req . httpRequest . headers [ 'Authorization' ] = `Bearer ${ bearerToken } `
228
+ const perflog = new PerfLog ( 'API request' )
227
229
228
230
return new Promise < T > ( ( resolve , reject ) => {
229
231
req . send ( function ( e , data ) {
230
232
const r = req as any
233
+ const timecost = perflog . elapsed ( ) . toFixed ( 1 )
231
234
if ( e ) {
232
235
if ( e . code === 'AccessDeniedException' || e . statusCode === 401 ) {
233
236
CodeCatalystClientInternal . identityCache . delete ( bearerToken )
@@ -237,19 +240,16 @@ class CodeCatalystClientInternal {
237
240
const logHeaders = { }
238
241
// Selected headers which are useful for logging.
239
242
const logHeaderNames = [
240
- // 'access-control-expose-headers',
241
- // 'cache-control',
242
- // 'strict-transport-security',
243
- 'x-amz-apigw-id' ,
244
- 'x-amz-cf-id' ,
245
- 'x-amz-cf-pop' ,
246
- 'x-amzn-remapped-content-length' ,
247
- 'x-amzn-remapped-x-amzn-requestid' ,
248
243
'x-amzn-requestid' ,
249
- 'x-amzn-served-from' ,
250
244
'x-amzn-trace-id' ,
245
+ 'x-amzn-served-from' ,
251
246
'x-cache' ,
252
- 'x-request-id' , // <- Request id for caws/fusi!
247
+ 'x-amz-cf-id' ,
248
+ 'x-amz-cf-pop' ,
249
+ // 'access-control-expose-headers',
250
+ // 'cache-control',
251
+ // 'strict-transport-security',
252
+ // 'x-amz-apigw-id',
253
253
]
254
254
if ( allHeaders && Object . keys ( allHeaders ) . length > 0 ) {
255
255
for ( const k of logHeaderNames ) {
@@ -260,21 +260,24 @@ class CodeCatalystClientInternal {
260
260
// Stack is noisy and useless in production.
261
261
const errNoStack = { ...e }
262
262
delete errNoStack . stack
263
- // Remove confusing "requestId" field (= "x-amzn-requestid" header)
264
- // because for caws/fusi, "x-request-id" is more relevant.
265
- // All of the various request-ids can be found in the logged headers.
266
- delete errNoStack . requestId
263
+ delete errNoStack . requestId // redundant (= "x-amzn-requestid" header).
267
264
268
265
if ( r . operation || r . params ) {
269
266
log . error (
270
- 'API request failed: %s\nparams: %O\nerror: %O\nheaders: %O' ,
267
+ 'API request failed (time: %dms): %s\nparams: %O\nerror: %O\nheaders: %O' ,
268
+ timecost ,
271
269
r . operation ,
272
- r . params ,
270
+ truncateProps ( r . params , 20 , [ 'nextToken' ] ) ,
273
271
errNoStack ,
274
272
logHeaders
275
273
)
276
274
} else {
277
- log . error ( 'API request failed:%O\nheaders: %O' , req , logHeaders )
275
+ log . error (
276
+ 'API request failed (time: %dms):%O\nheaders: %O' ,
277
+ timecost ,
278
+ truncateProps ( req , 20 , [ 'nextToken' ] ) ,
279
+ logHeaders
280
+ )
278
281
}
279
282
if ( silent ) {
280
283
if ( defaultVal === undefined ) {
@@ -286,7 +289,15 @@ class CodeCatalystClientInternal {
286
289
}
287
290
return
288
291
}
289
- log . verbose ( 'API request (%s):\nparams: %O\nresponse: %O' , r . operation ?? '?' , r . params ?? '?' , data )
292
+ if ( log . logLevelEnabled ( 'verbose' ) ) {
293
+ log . verbose (
294
+ 'API request (time: %dms): %s\nparams: %O\nresponse: %O' ,
295
+ timecost ,
296
+ r . operation ?? '?' ,
297
+ r . params ? truncateProps ( r . params , 20 , [ 'nextToken' ] ) : '?' ,
298
+ truncateProps ( data as object , 20 , [ 'nextToken' ] )
299
+ )
300
+ }
290
301
resolve ( data )
291
302
} )
292
303
} )
0 commit comments