Tracked exceptions not showing up in portal
See original GitHub issueI’ve added the insights sdk to my code in order to attempt to track errors in my code for function apps. I can’t use the default method of tracking failures for function apps (passing the error to context.done(error)), because that interrupts the HTTP response the function is supposed to give.
However, the exceptions do not show up in my insights instance. I assume the configuration is correct, since my custom events are showing up (although not associated with the actual request…is that supposed to happen?)
The test function I’m using:
module.exports = function (context, myTimer) {
const appInsights = require("applicationinsights");
appInsights.setAutoDependencyCorrelation(true);
const client = appInsights.getClient();
client.trackException(new Error("handled exceptions can be logged with this method"));
client.trackEvent('custom event');
context.log('JavaScript timer trigger function ran!');
context.done();
};
I don’t know whether this is a bug in the SDK or in the portal. Errors passed to context.done() are properly marked as exceptions in the portal.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Diagnose exceptions in web apps with Application Insights
In this article. Set up exception reporting; Diagnose exceptions using Visual Studio; Diagnose failures using the Azure portal; Custom tracing ...
Read more >Application Insights not tracking exceptions when used in ...
I am wanting to know if ServiceStack has any inbuilt exception handling that might be muting exceptions that are supposed to be caught...
Read more >Use Application Insights to solve exceptions - Patrick van Kleef
In this blog, I'll explain how exceptions are tracked and how Application Insights can be helpful for solving exceptions.
Read more >Appeals Status Lookup - HHS.gov
Welcome to AASIS. This system allows you to check the status of appeals you have filed with the Office of Medicare Hearings and...
Read more >Metrics Tracked for Storefront Exceptions and Error Messages
Track exceptions that a user can encounter on your storefront. From the Google Analytics™ console, ... Set Up Product Data for B2B Commerce...
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

The names do indeed seem backwards, but thanks to your explanation I understand them now.
I’ve got the correlation working the way I want to now, except for one small detail, but I don’t believe that’s fixable. I would like the requests in application insights to be associated with the operationId as well, however since they’re generated by the Azure Functions runtime I have no way of accessing their tags. I assume this is impossible for me to fix right now, since I only know the operationId once my function run has already started.
However, thank you so much for your help. You’ve helped me understand a great deal and achieve what I wanted, within the bounds of possibility. I look forward to seeing what kind of improvements you guys bring in the next couple of months!
Thanks for the follow up! I linked #148 not because of similar situations, but because a resolution is the same - a way to track requests without a req/res pair.
As for why they cannot be correlated, we simply don’t currently support automatic request collection for anything but the standard node server. Our correlation logic also correlates on requests, so without an automatically generated request context, or a manually generated one, you have no correlation.
Your suggested solution "so couldn’t you treat any function call following as a single request, if no other method is available " is interesting, but presents some issues. For example, it is a perfectly valid use case to use this SDK outside of a server context (eg, a desktop app using node like VSCode or Electron apps in general). In this situation, assuming a correlation context merely from the lack of requests could be unexpected behavior.
This all said, because you have a single client for each request, you can work around this for your particular use case with a telemetry processor. Code like the following may work for you (make sure it’s done before recording any telemetry):
We can look into creating an emulated response object if this workaround isn’t working out right - though the real solution is for us to stop requiring one to make request telemetry.