ApplicationInsights-node.js: Receiving "Zone already loaded" error when requiring AI client in Function App
Using applicationinsights@1.0.0 I am receiving this error, which causes the function to fail and respond 500:
2017-10-25T14:58:03.588 Exception while executing function: Functions.di-session-update
2017-10-25T14:58:03.588 Error: Zone already loaded.
at new Error (native)
at D:\home\site\wwwroot\node_modules\zone.js\dist\zone-node.js:25:15 [<root>]
at D:\home\site\wwwroot\node_modules\zone.js\dist\zone-node.js:971:3 [<root>]
at Zone.Zone.zoneSpec._properties (D:\home\site\wwwroot\node_modules\zone.js\dist\zone-node.js:9:68)
at Object.<anonymous> (D:\home\site\wwwroot\node_modules\zone.js\dist\zone-node.js:12:2)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at Module.patchedRequire [as require] (D:\home\site\wwwroot\node_modules\diagnostic-channel\dist\src\patchRequire.js:14:46)
at require (internal/module.js:20:19)
2017-10-25T14:58:03.588 Function completed (Failure, Id=9b458b5a-010e-4bbf-adaa-3616ea3de4b7, Duration=28ms)
2017-10-25T14:58:03.588 Executed 'Functions.di-session-update' (Failed, Id=9b458b5a-010e-4bbf-adaa-3616ea3de4b7)
This isn’t an issue for my other function which is part of the function app.
My functions currently share a package.json file between them, and I configure the ApplicationInsights client inside some shared library code, so I wonder if there’s something happening here which might cause the module to be included twice:
const appInsights = require('applicationinsights');
function setupInsights() {
/* omitted dev-only code which skips setup if process.env.NODE_ENV is dev */
appInsights.setup()
.setAutoCollectConsole(true, true) // Enable logging of all console methods.
.start();
return appInsights;
}
module.exports = setupInsights();
I had a look in CorrelationContextManager.js to see where it’s being required, but I’m not doing anything too special.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 21 (17 by maintainers)
Commits related to this issue
- Fix issue #346 — committed to microsoft/ApplicationInsights-node.js by OsvaldoRosado 6 years ago
- Fix bugs for 1.0.2 (#369) * Fix issue #362 * Fix issue #358 * Fix issue #346 * Fix issue #344 * Address issue #368 * Address issue #365 * Add additional logging and fix stability is... — committed to microsoft/ApplicationInsights-node.js by OsvaldoRosado 6 years ago
This should be fixed now in 1.0.2. Please reopen if you’re still seeing this!