Azure / react-appinsights

Typescript library to use Application Insights in React applications [deprecated, see microsoft/ApplicationInsights-JS]
MIT License
78 stars 32 forks source link

addTelemetryInitializer not called when initializing with ReactAI.init #71

Open lkohn opened 5 years ago

lkohn commented 5 years ago

Hi, There is an issue I've run into where when using addTelemetryInitializer to add custom meta data where it is not being called when initializing appinsights through React.AI but it does when initializing through AppInsights.downloadAndSetup.

Here is the code snippet I have for setting up the initializer: ` AppInsights.queue.push(function() { AppInsights.context.addTelemetryInitializer(function(envelope) { const telemetryItem = envelope.data.baseData; const userMeta = extractUserProfileFromState(store.getState());

telemetryItem.properties = telemetryItem.properties || {};
telemetryItem.properties["Application"] = APP_SETTINGS.moduleId;
if (userMeta) {
  telemetryItem.properties["User Name"] = userMeta.id;
}

}); }); Initializing throughAppInsights.downloadAndSetup` seems work even for the React component performance tracking so I'm inclined to leave it since everything is working now. I'm not sure if this is by design / a quirk / a bug but I figured you would want to know.

hiraldesai commented 5 years ago

Hi @lkohn - can you please advise which version of react-appinsights you're using? I'd recommend using the latest RC from here. Install it by running:

npm install --save react-appinsights@beta
lkohn commented 5 years ago

@hiraldesai We're using applicationinsights-js v1.0.20 and react-appinsights v2.0.2 . We'll give the @beta version a try and see if that helps.