Welcome to Microsoft Q&A! Thanks for posting the question.
Based on my understanding, you are using TrackException()
from applicationinsights
module to log exception to ApplicationInsights in your Node.js appliaction. By default, Node.js SDK for appInsights monitors incoming and outgoing HTTP requests, exceptions, and some system metrics. I tested a simple application and was able to get the exceptions logged to AppInsights.
Regarding the error being received, it looks like the error comes from inside the NodeClient.TelemetryClient.trackException()
which might be due to incorrect parameter. Please check if the passed parameter is of type error
and is being passed as telemetry.trackException({exception: ex});
Also, framework being used also impacts the behavior of exception. For example the "Express - Node.js web application framework" swallows all the exception and nothing gets written to applicationInsights. Here is the sample application that I tested which works as expected. I did not use any framework for this sample:
const appInsights = require('applicationinsights') //Imported at the beginning of my application
/****************/
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
/****************/
appInsights.setup("<<Instrumentation KEY>>")
.setSendLiveMetrics(true)
.setAutoCollectRequests(true)
.setAutoCollectPerformance(true, true)
.setAutoCollectExceptions(true)
.setDistributedTracingMode(appInsights.DistributedTracingModes.AI)
.start()
var telemetry = appInsights.defaultClient;
/****************/
const server = http.createServer((req, res) => {
try {
throw new Error('Exception message');
}
catch (ex) {
console.log(ex);
telemetry.trackException({exception: ex}); //Exception being tracked
}
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
The exception that was recorded contained the stack trace as below:
Can you please review the sample above and see if you are calling trackException()
with required parameter? In case this does not help, please share the complete error (along with the message) AND code snippet to better understand it.
Please let me know if you have any questions.
---
Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.