I am struggling with accomplishing the following scenario: I need to create a custom property for Application Insights, containing an identifier for the user (which is read from the data store at login time).
Went through several articles on the matter, but it does not seem to work.
I tried the following so far:
- Implemented a custom telemetry initializer and loaded it in a Sitecore pipeline. The problem here is that I can't access the session object, as it's always NULL. After some research I realized that it is triggered before the session is even created, so then I went to the second option.
- Tried to load the telemetry initializer in a
HttpRequestProcessor, I was able to access the session, but the Initialize method is never triggered afterwards. Can't say I understand what is happening. I added the initializer as follows
TelemetryConfiguration.Active.TelemetryInitializers.Add(new UserIdTelemetryInitializer([injected_service])), in the constructor of the processor, so it is only triggered once.
Does anyone have any thoughts on what exactly I am doing wrong? If you have a code example that works for you in a similar case, I would be grateful.
Let me know if you need additional information (might have been too brief about it).
I am registering the pipeline from option 2 in a patch file as follows:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"> <sitecore> <pipelines> <httpRequestProcessed> <processor type="[namespace].Pipelines.ApplicationInsights.UserIdTelemetryProcessor, [namespace]" resolve="true" /> </httpRequestProcessed> </pipelines> </sitecore>