-
Notifications
You must be signed in to change notification settings - Fork 237
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
[BUG] Application Insights reports 'not_specified' to Azure when tracking unhandled browser exception #1940
Comments
I found a related issue here, where it is recommended to use the correct syntax when calling trackException(). But the actual issue is not solved, i.e. AI itself calls trackException() with a string. |
This issue also rises here: |
We "should" be handling string "exceptions" and we have specific tests and code to handle this. But at least on looking at the code it does appear that when using the snippet a "string" won't necessarily be handled (it falls back to window.event so it will work on some browsers). For the scenario provided (using NPM) this should be working as it should come through this hook for the window.onerror https://github.com/microsoft/ApplicationInsights-JS/blob/master/extensions/applicationinsights-analytics-js/src/JavaScriptSDK/AnalyticsPlugin.ts#L699-L706 so it should "not" be calling trackException with a string value (the snippet onerror does look like this will happen) |
Just a note to inform that this issue is not forgotten, but due to scheduling conflicts, release lockdowns and holidays it's probably going to be early next year (2023) before I can carve out a decent amount of time to understand why strings are not always supported... I suspect that we will need to move the current string detecting code a little deeper in the stack. |
Allocating to the next release, but there is a risk (depending on the size of any required change) that it may not make this release. |
Great, thanks for following up! |
Ok, I've tried 4 scenarios
<button onclick="javascript: throw 'String Error'">Throw String Exception</button>
<button onclick="javascript: appInsights.trackException({ exception: 'String Error' })"">trackException with String as the exception</button>
<button onclick="javascript: try { throw 'String Error'; } catch(e) { appInsights.trackException({exception: e})}">trackException with try / catch</button>
<button onclick="javascript: appInsights.trackException('String Error')"">trackException with String</button> So while I could instead use our helper So you "should" be able to just use the following try {
throw 'TESTPIETER FULL';
}
catch (error) {
appInsights.trackException({
exception: error
});
} or just let the exception bubble up to the Here is a screendump of the For the one where I let it bubble to the And finally with The screen dumps where taken using F12 dev tools with the breakpoint @ Line 427 in 65fddb1
Shorter answer |
The PR that I've just pushed in (so it will be in the next release) provides a "fallback" cases for cases where someone passes a non- This has test coverage and appears to now be handling strings or Error instances directly (as well as null / undefined which should be the only cases for the "not_specified" now) |
Great! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description/Screenshot
Application Insights has automatic exception tracking enabled by default.
However, it seems to assume that the exception is always of type Error.
If the exception is simply a string, the trackException itself fails, throws an exception with message 'not_specified'.
Steps to Reproduce
Here is my setup:
When I throw a dummy exception with simply a string message in the console to test AI's auto trackException, this is what AI does:
(Stacktrace shown by using the @microsoft/applicationinsights-debugplugin-js plugin.)
It seems that AI then itself fails, as it does not expect a string, but an Error.
This it what is then reported to Azure:
If I throw an exception in code of type Error and catch it myself to manually call trackException(),
then I see the following:
And the error is correctly reported to Azure:
So, to me, it seems that AI exception tracking does not work correctly out of the box.
Currently, I would need to override the current global exception handler of the browser, to convert a string exception to an Error and call trackException() manually.
This should be done by AI itself out of the box.
The text was updated successfully, but these errors were encountered: