Granular Timing Debugging in Actions

Problem statement

If a tenant has a complicated Actions pipeline and there are issues, it can be hard to diagnose. Especially if the Action(s) contain individually a lot of code.

Solution

This debugging code can help isolate parts of the Actions pipeline that are causing the errors (specifically timeouts).

exports.onExecutePostLogin = async (event, api) => {
// Begin Timer at start of Action
  const startT = performance.now();
// Record Action name in log
  console.log("*** START [ACTION_NAME] - onExecutePostLogin ***");

// Perform external API CALL #1

// Calculate and print time taken after API Call above
  const partialT1 = performance.now();
  var totalT = partialT1 - startT;
  console.log(performance.now());
  console.log("*** Time taken for API CALL #1: ",totalT)

// Perform additional tasks #2

// Calculate and print time taken for above tasks #2
  const partialT2 = performance.now();
  var totalT = partialT2 - partialT1;
  console.log("*** Time taken for tasks #2: ",totalT)

// Calculate and print time taken for whole Action
  var totalT = performance.now() - startT;
  console.log("*** Time taken for Action: ",totalT)
  console.log("*** END [ACTION_NAME] - onExecutePostLogin ***");
}