CorrelationContext.getCurrentContext() returning undefined when deeply nested
See original GitHub issueOur auto-collected dependencies are inconsistently being correlated to the request (operation).
It appears that CorrelationContext.getCurrentContext() is working properly if called directly within the middleware (express) but if called further down (within callbacks and/or promises) it is returning undefined.
I have hacked in a workaround using continuation-local-storage:
var cls = require('continuation-local-storage');
var ns = cls.createNamespace('my.request');
//hack hack hack
var correlationContextManager = require('applicationinsights/out/AutoCollection/CorrelationContextManager').CorrelationContextManager;
var origGetCurrentContext = correlationContextManager.getCurrentContext;
function getCurrentContext(){
return ns.get('ctx') || origGetCurrentContext();
}
correlationContextManager.getCurrentContext = getCurrentContext;
module.exports = function (req, res, next) {
ns.bindEmitter(req);
ns.bindEmitter(res);
ns.run(function(){
ns.set('ctx', origGetCurrentContext());
next();
});
};
We have all auto-collection enabled:
appInsights.setup(config.appInsightsKey)
.start();
We use bluebird promises heavily, which may affect how the underlying zones function.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Automated Malware Analysis Report for f_00002a
_loadApplicationContext = function (packageJsonPath) {.. var version = "unknown";.. var description = undefined;.. try {.. // note: this should return the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Closing this as Zone.js has been deprecated in favor of cls-hooked, so this is likely no longer an issue
This looks to me like you’re seeing the effects of multiple versions of zone.js being loaded. Notably the version of zone.js currently depended on in this SDK does not include the bluebird patch files or the
__load_patchmethod it uses. This makes me suspect you’ve npm installed another version ofzone.jsthat’s incompatible. We should perhaps switchzone.jsto peerDependency so this isn’t possible