title: When can I get an Application Insights operation id?
body: <p>I have a AspNetCore web app that writes to EventHub and a webjob that reads from it. I'd like the telemetry from both parts of this transaction to have the same operation id in Application Insights.</p>
  
  <p>So, when I'm about to send the data to EventHub I try to pull the operation id out of the TelemetryClient, e.g.</p>
  
  <pre><code>var myOperationId = MyTelemetryClient.Context.Operation.Id;
  </code></pre>
  
  <p>But this always gives me null. I found this <a href="https://dzimchuk.net/post/event-correlation-in-application-insights" rel="noreferrer">article</a> and tried using</p>
  
  <pre><code>var request.HttpContext.Items["Microsoft.ApplicationInsights.RequestTelemetry"] as RequestTelemetry;
  </code></pre>
  
  <p>But again null. Any pointers on a way I can extract this value when I need it?</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>public class Startup
  {
      public void ConfigureServices( IServiceCollection IServices )
      {
          var builder = TelemetryConfiguration.Active.TelemetryProcessorChainBuilder;
          builder.Use((next) =&gt; new MyTelemetryProcessor(next));
          builder.Build();
  
          var aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
          aiOptions.EnableQuickPulseMetricStream = true;
  
          IServices.AddApplicationInsightsTelemetry( Configuration, aiOptions);
          IServices.AddMvc();
          IServices.AddOptions();
  
          TelemetryClient AppTelemetry = new TelemetryClient();
          AppTelemetry.InstrumentationKey = InsightsInstrumentationKey;
          IServices.AddSingleton(typeof(TelemetryClient), AppTelemetry);
      }
      public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory )
      {
          app.UseApplicationInsightsRequestTelemetry();
          app.UseApplicationInsightsExceptionTelemetry();
  
          app.UseMvc();
  
          var configuration = app.ApplicationServices.GetService&lt;TelemetryConfiguration&gt;();
          configuration.TelemetryInitializers.Add(new MyTelemetryInitializer());
      }
  }
  
  [Route("[controller]")]
  public class MyController
  {
      private readonly TelemetryClient mTelemetryClient;
  
      public MyController(
          TelemetryClient TelemetryClientArg)
      {
          mTelemetryClient = TelemetryClientArg;
      }
  
      [HttpPost]
      public async Task&lt;IActionResult&gt; Post([FromBody]MyPostDataClass MyPostData)
      {
          string telemetryId = mTelemetryClient.Context.Operation.Id; // this is null
  
          return Ok();
      }
  }
  </code></pre>