microsoft / applicationinsights-react-js

Microsoft Application Insights React plugin
MIT License
35 stars 13 forks source link

[BUG] Consuming trackEvent from useAppInsights results in DynamicProto error #121

Open DZetko opened 2 weeks ago

DZetko commented 2 weeks ago

Description/Screenshot I have below React component

` import React from "react"; import { useAppInsightsContext } from "@microsoft/applicationinsights-react-js"; const TestComponent = () => { const { trackEvent } = useAppInsightsContext();

function onClick() {
    trackEvent({ name: "TestComponent test" });
}

return (
    <div className="App">
        <div>
            <button onClick={onClick}>Add Number</button>
        </div>
    </div>
);

}; export default TestComponent; `

When I click the Add Number button, I am getting bellow error message: Image

My Application Insights instance is set up as below

Image

Steps to Reproduce

Expected behavior Error should not be displayed and event should be sent to Application Insights.

Additional context Add any other context about the problem here.

When using reactPlugin instance directly and calling reactPlugin.trackEvent works.

MSNev commented 1 week ago

When you see this error this is caused by either of the following

Personally, I've only seen the first case where a combination of npm and snippet was being used, so your local code is including 1 copy of the source code and using that, but the SDK Loader comes along behind you and "overwrites" the global namespace of the code "Microsoft.ApplicationInsights.XXX".

The latest version of the code (v3.x) is aware of this situation and the default "initialization" code added to the top of each bundle trys to avoid "overwriting" the class / object definitions. By

Image

So what does all this mean?

Please check whether your runtime is