-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trackException in express middleware doesn't get correlation context when using autoCorrelation #566
Comments
Which version of the SDK are you using? I'm unable to repro this locally with this sample app. const Promise = require('bluebird');
global.Promise = Promise;
Promise.longStackTraces();
const appInsights = require('applicationinsights');
appInsights.setup('ikey')
.setSendLiveMetrics(true)
.start();
const express = require('express');
const app = express();
app.get('/', (req, res) => {
console.log(appInsights.getCorrelationContext());
throw new Error();
});
app.use((err, req, res, next) => {
console.log(appInsights.getCorrelationContext());
res.sendStatus(500);
});
app.listen(3000); There may be an issue with async stuff however, in which case you would need to bind the current context to any new async operations ( |
It's v1.5.0. I'll take a look at the sample and try adding some getCorrelationContext calls into my code to see where it gets lost. Thanks! |
I have the same problem... It's lost immediately :( index.js const appInsights = require('applicationinsights');
appInsights.setup(process.env.APPINSIGHTS_INSTRUMENTATIONKEY)
.setAutoDependencyCorrelation(true, true)
.setAutoCollectRequests(true)
.setAutoCollectPerformance(true)
.setAutoCollectExceptions(true)
.setAutoCollectDependencies(true)
.setAutoCollectConsole(true, true)
.setUseDiskRetryCaching(true)
.setSendLiveMetrics(true)
.start();
console.log('CONTEXT', appInsights.getCorrelationContext()); // null :( "apollo-datasource-rest": "^0.5.0",
"apollo-server-azure-functions": "^2.6.8",
"apollo-server-core": "latest",
"applicationinsights": "^1.7.2",
"azure-functions-core-tools": "^2.7.1585" Using Azure function. So all dependencies and exceptions in AppInsights are with no |
It seems to be an issue with the promise chain calling out to the database. I've been able to get a context for most of my errors by wrapping all of the calls to |
running into the same issue, I need to create a correlating context outside of express (in a MQ) and all examples just assume a context is already created and getCorrelationContext() just returns null @shatodj did u figure this out |
Hey @Mike-Fink-Jr . YES. We used const appInsights = require("applicationinsights");
const withCorrelationContext = (invocationContext, req) => (handler) => {
// Start an AI Correlation Context using the provided Function context
const correlationContext = appInsights.startOperation(invocationContext, req);
// Wrap the Function runtime with correlationContext
return appInsights.wrapWithCorrelationContext(() => handler(invocationContext, req), correlationContext)();
}
const runHandler = (context, request) => {
// our azure function intergation
}
module.exports = {
run: (context, req) => withCorrelationContext(context, req)(runHandler),
}; I hope that helps. |
|
I've got an express app set up like this:
./application-insights.js
sets up the library like this:And the error handler middleware does this:
However, while I see requests and exceptions coming through in the Azure portal, they're not correlated together. I've tried debugging through the tracking calls, and it seems that in the
trackException
call, the call togetTag
in the message envelope:returns a
null
correlationContext. I'm sure I'm doing something wrong, but I can't figure out what!The text was updated successfully, but these errors were encountered: