0
votes

I am struggling with the problem that I'm getting a lot of the exceptions in Azure Application Insights with this error message: Script error: The browser's same-origin policy prevents us from getting the details of this exception. Consider using the 'crossorigin' attribute.

I understand that I need to add crossorigin="anonymous" to the script tag, but the problem is that these errors are generated from Ads script (which also loads other scripts) on our site, so I can't actually put that attribute for all of them.

Basically I don't even care about these errors, so I just don't want to send them to the Application Insights at all. I've added the telementry initializer, which I expected will work to filter the errors, but I still receive a lot of that errors (~100.000 per day). Here is the initializer filtering I tried:

ai.addTelemetryInitializer((item) => {
    if (item.baseType == "ExceptionData" && item.baseData &&
        item.baseData.exceptions && item.baseData.exceptions.length > 0 && 
        item.baseData.exceptions[0].message.startsWith("Script error:")) {
        return false;
    }
});

Also I've tried to filter it by item.baseData.error, but that also didn't help.

How should I configure the telemetry initializer so I can skip these errors?

1
Are you getting this error in F12 dev tools console? Or actually in Application Insights? My experience is that browsers don't expose details for any CORS-related errors. Instead it is just a plain failure without reasons. It might be tricky to filter such out.ZakiMa
@ZakiMa, no, I tried to replicate this locally or catch it in production in the dev tools console, but with no luck. I see the error only in the Application Insights exception logs.Roman Kudryk

1 Answers

0
votes

You can use Sampling in Application Insights to reduce/skip the errors.

  • <InitialSamplingPercentage>100</InitialSamplingPercentage> : The amount of telemetry to sample when the app has just started.

  • <ExcludedTypes>Trace;Exception</ExcludedTypes> : A semi-colon delimited list of types that you do not want to be subject to sampling. Recognized types are: Dependency, Event, Exception, PageView, Request, Trace.

You can refer to How to exclude Exception and Error logging from sampling in Application Insights in .NET Core 2.1?, Filter and preprocess telemetry in the Application Insights SDK and No way to suppress cross-domain script errors from logging?