@@ -8,10 +8,13 @@ import {
8
8
GetApisCommand ,
9
9
} from "@aws-sdk/client-apigatewayv2" ;
10
10
import { acquireLock , releaseLock } from "../lib/locks" ;
11
+ import Logger from "../lib/logger" ;
11
12
12
13
const supportedRuntimes = [ "nodejs16.x" , "nodejs18.x" , "nodejs20.x" ] ;
13
14
const lambdaExecWrapper = "/opt/nodejs/tracer_wrapper" ;
14
15
16
+ const logger = new Logger ( "auto-trace" ) ;
17
+
15
18
const getAccountLambdas = async ( ) => {
16
19
const lambdaClient = new LambdaClient ( ) ;
17
20
@@ -21,7 +24,7 @@ const getAccountLambdas = async () => {
21
24
do {
22
25
const listFunctionsCommand = new ListFunctionsCommand ( {
23
26
Marker : nextToken ,
24
- MaxItems : 50
27
+ MaxItems : 50 ,
25
28
} ) ;
26
29
const { Functions, NextMarker } =
27
30
await lambdaClient . send ( listFunctionsCommand ) ;
@@ -62,7 +65,7 @@ export const autoTrace = async () => {
62
65
// Make sure we lock so that only one process is updating lambdas
63
66
const lockAcquired = await acquireLock ( "auto-trace" ) ;
64
67
if ( ! lockAcquired ) {
65
- console . log ( "Lock not acquired, skipping" ) ;
68
+ logger . info ( "Lock not acquired, skipping" ) ;
66
69
return ;
67
70
}
68
71
@@ -96,7 +99,7 @@ export const autoTrace = async () => {
96
99
) ;
97
100
} ) ;
98
101
99
- console . log ( `Found ${ lambdasWithoutLayer . length } lambdas to update` ) ;
102
+ logger . info ( `Found ${ lambdasWithoutLayer . length } lambdas to update` ) ;
100
103
101
104
for ( const lambda of lambdasWithoutLayer ) {
102
105
try {
@@ -122,13 +125,13 @@ export const autoTrace = async () => {
122
125
const res = await new LambdaClient ( ) . send (
123
126
updateFunctionConfigurationCommand ,
124
127
) ;
125
- console . log ( res ) ;
128
+ logger . info ( res ) ;
126
129
127
- console . log ( `✓ Updated ${ lambda . FunctionName } ` ) ;
130
+ logger . info ( `✓ Updated ${ lambda . FunctionName } ` ) ;
128
131
// TODO: save function info in DynamoDB
129
132
} catch ( e ) {
130
- console . log ( `✗ Failed to update ${ lambda . FunctionName } ` ) ;
131
- console . error ( e ) ;
133
+ logger . warn ( `✗ Failed to update ${ lambda . FunctionName } ` ) ;
134
+ logger . warn ( e ) ;
132
135
}
133
136
}
134
137
0 commit comments