title: Application Insights - Tracking user and session across schemas
body: <p>Following <a href="https://docs.microsoft.com/en-us/azure/application-insights/app-insights-usage-send-user-context" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/application-insights/app-insights-usage-send-user-context</a>, I thought it would be easy to get cross-schema tracking of a user.  However, I'm finding the absolute opposite.  </p>
  
  <p>I created the telemetry initializer (which the document has bugs in it hardcore):</p>
  
  <pre><code>public void Initialize(ITelemetry telemetry)
      {
          if (HttpContext.Current?.Session == null)
              return;
  
          if (HttpContext.Current.Session["UserId"] == null)
          {
              HttpContext.Current.Session["UserId"] = Guid.NewGuid().ToString();
          }
  
          telemetry.Context.User.Id = (string)HttpContext.Current.Session["UserId"];
          telemetry.Context.Session.Id = HttpContext.Current.Session.SessionID;
  
          var authUser = _sessionManager.GetAuthenticatedUser&lt;UserDetails&gt;();
          if (authUser != null)
          {
              telemetry.Context.User.AuthenticatedUserId = authUser.UserId;
          }
      }
  </code></pre>
  
  <p>Then I went and added it to App Insights</p>
  
  <pre><code>TelemetryConfiguration.Active.TelemetryInitializers.Add(new UserTrackingTelemetryInitializer());
  </code></pre>
  
  <p>I then played with my site, expecting this stuff to start showing up.  It did not. I continued to get random strings for user_Id and session_Id (things like NVhLF and what not).  So, I thought, okay, maybe it's logging before I update those values?  I went and inserted my initializer first:</p>
  
  <pre><code>TelemetryConfiguration.Active.TelemetryInitializers.Insert(0, new UserTrackingTelemetryInitializer());
  </code></pre>
  
  <p>Same thing.  So I started to look at schemas I don't usually look at.  Nothing.  So I pulled up traces and I found it.  Finally, there is where my data is going.  But the other schemas don't have the updated values, so what use is this?  While traces is showing the expected values for user_Id and session_Id, the others continue to show garbage.  Am I doing something wrong?</p>