using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyLibrary.Web.Context;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
namespace ACME.Foundation.Analytics
{
public class ApplicationInsightsSessionInitializer : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
var requestTelemetry = telemetry as RequestTelemetry;
if (requestTelemetry == null) return;
if (HttpContext.Current.Session.SessionID != null)
{
telemetry.Context.Session.Id = HttpContext.Current.Session.SessionID;
}
}
}
}
In ApplicationInsights.config
<Add Type="ACME.Foundation.Analytics.ApplicationInsightsSessionInitializer, ACME.Foundation.Analytics" />
<Add Type="Microsoft.ApplicationInsights.StatusMonitor.SdkSourceTelemetryInitializer, Microsoft.AI.StatusMonitor" />
How do I get session id from requestTelemetry? I have this snippet in my analytics telemetry folder. It seems as if the itemType Request does not have a a session ID. Everytime a request appears, the session is null.
I'd like to match it with the proper sessionID, and can't override it in the app insights sessionID
I was following the example here: https://learn.microsoft.com/en-us/azure/application-insights/app-insights-usage-send-user-context
and based my solution on the demo located halfway down the page, but doesn't seem to be working for me.
Any help would be appreciated!