Azure / azure-functions-nodejs-worker

The Node.js worker for the Azure Functions runtime - https://functions.azure.com
MIT License
106 stars 44 forks source link

Fix startup error not showing up in kusto #753

Closed ejizba closed 3 months ago

ejizba commented 3 months ago

Found this bug a couple weeks ago when Thiago was debugging a bad node v4 app on flex.

Repro steps

  1. Create a v4 app
  2. Use Node 20
  3. Delete the http trigger code and add throw new Error('test'); instead
  4. Run your app
  5. Wait a while then check app insights & kusto

Expected

The error shows up in customer's app insights and our kusto

Actual

The error only shows up in customer's app insights, but not kusto

More info

Today, we save app startup errors that happen during workerInitRequest and return them during functionsMetadataRequest or functionLoadRequest instead (which also logs them - which is what I care about for this PR). However, if the error happens for a v4 app before the v4 model is registered in user code, we skip sending the error during functionsMetadataRequest because we think it's a v3 app and the host never sends a functionLoadRequest which only applies to v3 apps.

My fix is to always log the error right away and set a flag to prevent it from potentially being duplicated later.