Skip to content
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

Unhandled browser exceptions not being tracked. #282

Closed
acg9 opened this issue Jul 28, 2016 · 6 comments
Closed

Unhandled browser exceptions not being tracked. #282

acg9 opened this issue Jul 28, 2016 · 6 comments
Assignees
Labels
Milestone

Comments

@acg9
Copy link

acg9 commented Jul 28, 2016

I've included the applicationinsights-js module and initialized it with my instrumentation key. I also tried tracking page views which do show up in the azure portal.

I've been trying to get unhandled browser exceptions to show up in the portal with no success. I've tried manually throwing the exceptions or faking invalid operations but neither of them are tracked by app insights. Is there something I'm missing or any way to get logging to show if app insights is ignoring my exceptions?

I encountered this issue with this javascript example and this example with typescript.

@KamilSzostak
Copy link
Contributor

There are two configuration settings which can help with debugging - see IConfig. They are both set to false by default. You can enabled them in the snippet in the config object.

    enableDebug: boolean;

    verboseLogging: boolean;

@acg9
Copy link
Author

acg9 commented Aug 4, 2016

I tried enabling 'enableDebug' and 'verboseLogging' and I still don't see any exception data.

Here's a sample of our code:

import {AppInsights} from "applicationinsights-js";

AppInsights.downloadAndSetup({
    instrumentationKey: "something",
    enableDebug: true,
    verboseLogging: true
});

AppInsights.trackPageView("Test");

throw 5;

With this I can see the 'Test' page view in the azure app insights portal but not the exception. Where am I supposed to see the verbose logging? The only thing the Chrome console shows is the uncaught exception message.

@tdekoning
Copy link

I'm experiencing the same issue, any idea when we can see a solution for this?

@KamilSzostak KamilSzostak added bug and removed question labels Nov 17, 2016
@KamilSzostak KamilSzostak added this to the 1.0.6 milestone Nov 17, 2016
@KamilSzostak KamilSzostak self-assigned this Nov 17, 2016
@ArturDorochowicz
Copy link

I think I'm experiencing the same issue.

Isn't the problem the fact that it's not onerror that is registered (and 'original' of which is captured) on window, but _onerror?

In AppInsightsModule.ts [1]:

        // collect global errors
        if (!aiConfig.disableExceptionTracking) {
            AppInsightsModule._createLazyMethod("_onerror");
            var originalOnError = window["_onerror"];
            window["_onerror"] = function (message, url, lineNumber, columnNumber, error) {
                var handled = originalOnError && originalOnError(message, url, lineNumber, columnNumber, error);
                if (handled !== true) {
                    aiObject["_onerror"](message, url, lineNumber, columnNumber, error);
                }

                return handled;
            };
        }

AFAIS this is different than snippet.js [2]

    // collect global errors
    if (!aiConfig.disableExceptionTracking) {
        method = "onerror";
        createLazyMethod("_" + method);
        var originalOnError = localWindow[method];
        localWindow[method] = function(message, url, lineNumber, columnNumber, error) {
            var handled = originalOnError && originalOnError(message, url, lineNumber, columnNumber, error);
            if (handled !== true) {
                appInsights["_" + method](message, url, lineNumber, columnNumber, error);
            }

            return handled;
        };
    }

[1] https://github.com/Microsoft/ApplicationInsights-JS/blob/f42f662bcb1669c791552382a395d5e2451b69b7/JavaScript/JavaScriptSDK.Module/AppInsightsModule.ts#L78

[2] https://github.com/Microsoft/ApplicationInsights-JS/blob/f42f662bcb1669c791552382a395d5e2451b69b7/JavaScript/JavaScriptSDK/snippet.js#L61

@KamilSzostak
Copy link
Contributor

KamilSzostak commented Mar 21, 2017

This is happening when you throw an error in the snippet's <script> block. The snippet is trying to loading the full SDK (the ai.0.js file), but because of an error the browser doesn't finish the operation and the SDK is never fully initialized.

You can bypass this limitation by throwing error in a different <script> block.

<script type="text/javascript">
    [snippet goes here]
</script>
<script type="text/javascript">
    throw new Error("uppps");
</script>

EDIT: I fixed the snippet to capture errors thrown from the snippet's script block - #427.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants