How to process tracked information in Application Insights

Tags: , , ,



I am using Application Insights to track events in my web pages:

appInsights.trackEvent("my-event", { test: true });

However I can see that each entry in the log, collects some info regarding several other things like:

  • User Id
  • Session Id
  • Operation name

The last one is sensitive as I can get the name of the computer or some other stuff. In order to comply to the GDPR, I wanna strip out those info from my log.

How do I tell Application Insights, to process the data before logging them? In my case, I would like to get access to the object which will be sent out by trackEvent and modify it before it is transmitted.

Answer

You can use TelemetryInitializers for that. They allow you to modify items before they are send to Application Insights

In your case it could be as simple as

appInsights.queue.push(function () {
    appInsights.context.addTelemetryInitializer(function (envelope) {
        envelope.tags['ai.operation.name'] = 'xxx';
});


Source: stackoverflow