Skip to content

Commit

Permalink
Add lambda runtime execution info logging (#2177)
Browse files Browse the repository at this point in the history
* Add lambda runtime execution info logging

* Fix tests
  • Loading branch information
timbset authored Dec 14, 2021
1 parent fc7b110 commit 09c0c6b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/core/debug-levels/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import debug, { Debug, Debugger } from 'debug'

const logLevels = ['log', 'error', 'warn', 'debug', 'info', 'verbose']
const logLevels = ['error', 'warn', 'log', 'debug', 'info', 'verbose']
const defaultLogLevel = logLevels[3]

type Logger = (...args: any[]) => void
Expand Down
2 changes: 1 addition & 1 deletion packages/core/debug-levels/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ test('should work with provided DEBUG and DEBUG_LEVEL envs', () => {

expect(debugProvider).toBeCalledWith('namespace')

expect(debugPrinter).toBeCalledWith('Log message')
expect(debugPrinter).toBeCalledWith('Error message')
expect(debugPrinter).toBeCalledWith('Warn message')
expect(debugPrinter).not.toBeCalledWith('Log message')
expect(debugPrinter).not.toBeCalledWith('Debug message')
expect(debugPrinter).not.toBeCalledWith('Info message')
expect(debugPrinter).not.toBeCalledWith('Verbose message')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import type {

const log = getLog('lambda-worker')

const logRuntimeCase = (caseName: string) =>
log.log(`Runtime execution: ${caseName}`)

const GRACEFUL_WORKER_SHUTDOWN_TIME = 30 * 1000
const getLambdaVacantTime = (lambdaContext: any) =>
lambdaContext.getRemainingTimeInMillis() - GRACEFUL_WORKER_SHUTDOWN_TIME
Expand Down Expand Up @@ -108,7 +111,7 @@ export const lambdaWorker = async (

try {
if (lambdaEvent.resolveSource === 'DeployService') {
log.debug('identified event source: deployment service')
logRuntimeCase('DeployService')
void ({ runtime } = await makeRuntime({}))

const executorResult = await handleCloudServiceEvent(
Expand All @@ -132,7 +135,7 @@ export const lambdaWorker = async (

return executorResult
} else if (lambdaEvent.resolveSource === 'BuildEventSubscriber') {
log.debug('identified event source: event-subscriber-direct')
logRuntimeCase('BuildEventSubscriber')
void ({ runtime } = await makeRuntime({}))

const { resolveSource, eventSubscriber, ...buildParameters } = lambdaEvent
Expand All @@ -157,6 +160,7 @@ export const lambdaWorker = async (
),
].every((key) => key === 'aws:sqs')
) {
logRuntimeCase('SQS')
const errors = []
const records = lambdaEvent.Records.map((record: LambdaEventRecord) => {
try {
Expand Down Expand Up @@ -240,7 +244,7 @@ export const lambdaWorker = async (

return executorResult
} else if (lambdaEvent.resolveSource === 'Scheduler') {
log.debug('identified event source: cloud scheduler')
logRuntimeCase('Scheduler')

const data = await makeRuntime({})

Expand All @@ -253,7 +257,8 @@ export const lambdaWorker = async (

return executorResult
} else if (lambdaEvent.resolveSource === 'Websocket') {
log.debug('identified event source: websocket')
logRuntimeCase('Websocket')

void ({ runtime } = await makeRuntime({}))

const executorResult = await handleWebsocketEvent(
Expand All @@ -265,6 +270,8 @@ export const lambdaWorker = async (

return executorResult
} else if (lambdaEvent.headers != null && lambdaEvent.httpMethod != null) {
logRuntimeCase('API')

const overrideParams =
lambdaEvent.requestStartTime !== undefined &&
Number.isSafeInteger(lambdaEvent.requestStartTime)
Expand All @@ -282,7 +289,6 @@ export const lambdaWorker = async (

runtime.eventStoreAdapter.establishTimeLimit(data.getVacantTimeInMillis)

log.debug('identified event source: API gateway')
log.verbose(
JSON.stringify(lambdaEvent.httpMethod, null, 2),
JSON.stringify(lambdaEvent.headers, null, 2)
Expand Down

0 comments on commit 09c0c6b

Please sign in to comment.