src/index.js
function installTimers(pluginConfig, lambdaContext) {
	const timeRemaining = lambdaContext.getRemainingTimeInMillis();
	const memoryLimit = lambdaContext.memoryLimitInMB;

	function timeoutWarningFunc(cb) {
		const Raven = pluginConfig.ravenClient;
		ravenInstalled && Raven.captureMessage("Function Execution Time Warning", {
			level: "warning",
			extra: {
				TimeRemainingInMsec: lambdaContext.getRemainingTimeInMillis()
			}
		}, cb);
	}

	function timeoutErrorFunc(cb) {
		const Raven = pluginConfig.ravenClient;
		ravenInstalled && Raven.captureMessage("Function Timed Out", {
			level: "error",
			extra: {
				TimeRemainingInMsec: lambdaContext.getRemainingTimeInMillis()
			}
		}, cb);
	}

	function memoryWatchFunc(cb) {
		const used = process.memoryUsage().rss / 1048576;
		const p = (used / memoryLimit);
		if (p >= 0.75) {
			const Raven = pluginConfig.ravenClient;
			ravenInstalled && Raven.captureMessage("Low Memory Warning", {
				level: "warning",
				extra: {
					MemoryLimitInMB: memoryLimit,
					MemoryUsedInMB: Math.floor(used)
				}
			}, cb);

			if (memoryWatch) {
				clearTimeout(memoryWatch);
				memoryWatch = null;
			}
		}
		else {
			memoryWatch = setTimeout(memoryWatchFunc, 500);
		}
	}

	if (pluginConfig.captureTimeoutWarnings) {
		// We schedule the warning at half the maximum execution time and
		// the error a few milliseconds before the actual timeout happens.
		timeoutWarning = setTimeout(timeoutWarningFunc, timeRemaining / 2);
		timeoutError = setTimeout(timeoutErrorFunc, Math.max(timeRemaining - 500, 0));
	}

	if (pluginConfig.captureMemoryWarnings) {
		// Schedule memory watch dog interval. Note that we're not using
		// setInterval() here as we don't want invokes to be skipped.
		memoryWatch = setTimeout(memoryWatchFunc, 500);
	}
}
function installTimers(pluginConfig, lambdaContext) {
	const timeRemaining = lambdaContext.getRemainingTimeInMillis();
	const memoryLimit = lambdaContext.memoryLimitInMB;

	function timeoutWarningFunc(cb) {
		const Raven = pluginConfig.ravenClient;
		ravenInstalled && Raven.captureMessage("Function Execution Time Warning", {
			level: "warning",
			extra: {
				TimeRemainingInMsec: lambdaContext.getRemainingTimeInMillis()
			}
		}, cb);
	}

	function timeoutErrorFunc(cb) {
		const Raven = pluginConfig.ravenClient;
		ravenInstalled && Raven.captureMessage("Function Timed Out", {
			level: "error",
			extra: {
				TimeRemainingInMsec: lambdaContext.getRemainingTimeInMillis()
			}
		}, cb);
	}

	function memoryWatchFunc(cb) {
		const used = process.memoryUsage().rss / 1048576;
		const p = (used / memoryLimit);
		if (p >= 0.75) {
			const Raven = pluginConfig.ravenClient;
			ravenInstalled && Raven.captureMessage("Low Memory Warning", {
				level: "warning",
				extra: {
					MemoryLimitInMB: memoryLimit,
					MemoryUsedInMB: Math.floor(used)
				}
			}, cb);

			if (memoryWatch) {
				clearTimeout(memoryWatch);
				memoryWatch = null;
			}
		}
		else {
			memoryWatch = setTimeout(memoryWatchFunc, 500);
		}
	}

	if (pluginConfig.captureTimeoutWarnings) {
		// We schedule the warning at half the maximum execution time and
		// the error a few milliseconds before the actual timeout happens.
		timeoutWarning = setTimeout(timeoutWarningFunc, timeRemaining / 2);
		timeoutError = setTimeout(timeoutErrorFunc, Math.max(timeRemaining - 500, 0));
	}

	if (pluginConfig.captureMemoryWarnings) {
		// Schedule memory watch dog interval. Note that we're not using
		// setInterval() here as we don't want invokes to be skipped.
		memoryWatch = setTimeout(memoryWatchFunc, 500);
	}
}
function installTimers ( pluginConfig , lambdaContext ) { const timeRemaining = lambdaContext . getRemainingTimeInMillis ( ) ; const memoryLimit = lambdaContext . memoryLimitInMB ; function timeoutWarningFunc ( cb ) { const Raven = pluginConfig . ravenClient ; ravenInstalled && Raven . captureMessage ( "Function Execution Time Warning" , { level : "warning" , extra : { TimeRemainingInMsec : lambdaContext . getRemainingTimeInMillis ( ) } } , cb ) ; } function timeoutErrorFunc ( cb ) { const Raven = pluginConfig . ravenClient ; ravenInstalled && Raven . captureMessage ( "Function Timed Out" , { level : "error" , extra : { TimeRemainingInMsec : lambdaContext . getRemainingTimeInMillis ( ) } } , cb ) ; } function memoryWatchFunc ( cb ) { const used = process . memoryUsage ( ) . rss / 1048576 ; const p = ( used / memoryLimit ) ; if ( p >= 0.75 ) { const Raven = pluginConfig . ravenClient ; ravenInstalled && Raven . captureMessage ( "Low Memory Warning" , { level : "warning" , extra : { MemoryLimitInMB : memoryLimit , MemoryUsedInMB : Math . floor ( used ) } } , cb ) ; if ( memoryWatch ) { clearTimeout ( memoryWatch ) ; memoryWatch = null ; } } else { memoryWatch = setTimeout ( memoryWatchFunc , 500 ) ; } } if ( pluginConfig . captureTimeoutWarnings ) { // We schedule the warning at half the maximum execution time and // the error a few milliseconds before the actual timeout happens. timeoutWarning = setTimeout ( timeoutWarningFunc , timeRemaining / 2 ) ; timeoutError = setTimeout ( timeoutErrorFunc , Math . max ( timeRemaining - 500 , 0 ) ) ; } if ( pluginConfig . captureMemoryWarnings ) { // Schedule memory watch dog interval. Note that we're not using // setInterval() here as we don't want invokes to be skipped. memoryWatch = setTimeout ( memoryWatchFunc , 500 ) ; } }
Insatll Watchdog timers

@param {Object} pluginConfig
@param {Object} lambdaContext
Insatll Watchdog timers