microsoft / ApplicationInsights-JS

Microsoft Application Insights SDK for JavaScript
MIT License
650 stars 240 forks source link

[BUG] [Snippet] Unhandled exceptions are reported twice #2442

Open VitaliyPotapov opened 1 week ago

VitaliyPotapov commented 1 week ago

Description/Screenshot When using appInsights as a snippet, unhandled exceptions are reported twice.

Screenshot: Image

Steps to Reproduce

  1. Open reproduction demo: https://7rslpk.csb.app/ ( https://codesandbox.io/p/sandbox/7rslpk )
  2. Open devtools network tab
  3. Wait for second request to /track and check the payload

Expected behavior Only one unhandled exception is reported.

Additional context

MSNev commented 6 days ago

Ok, I've just tracked through your provided reproduction THANK YOU VERY MUCH, it was extremely helpful to identify this specific scenario.

The issue lies around in the changes that we have made for "populating" (and exposing) the dynamic config (so this bug has now been here for quite a while 😦 ) and how the snippet "informs" the main SDK that it has already "hooked" the window.onerror (so that it doesn't do it again)

As we have just released the final (planned) release for this year (because we are just entering the holiday lock down period) and we are limited in our ability to promote SDK versions to production unless they are required for high priority issues, lets start with a way for you to avoid this issue that I have identified.

Temporary Workaround

As a temporary work-around (until we can release a fixed version), you can add the following to the configuration that you pass to the snippet (SDK Loader)

        connectionString: " ... Removed ...",
        extensionConfig: {
          ApplicationInsightsAnalytics: {
            autoExceptionInstrumented: true
          }
        }

This will then populate the (internalish) flag that the snippet uses to inform the sdk that it has already hooked the onerror, into the location that the SDK is now looking at.

I'll add some more "fix" notes in a follow up comment as I have to run to a meeting right now.

MSNev commented 6 days ago

As part of fixing this the core SDK needs to either

Or a combination of the above, there may also be other alternative solutions that I have not yet identified.

VitaliyPotapov commented 6 days ago

Thanks for the reply and the workaround. I confirm it works!