title: Application Insights Telemetry Missing in .Net Core 3 app Running in Docker Container
body: <p>We have a small API hosted in AKS which was written using .Net core 2.2. It has been working fine and we have seen all our App Insights telemetry in the Azure portal, both in Live Metrics and Log Analytics as expected. We recently encountered a problem during a long running process which gave us an unhelpful error message, but it seems that upgrading to .Net core 3 or higher provides more information when it occurs, so we set about upgrading. We went straight for 3.1, upgraded all packages (including the AI package) to ensure they were all 3.1 compatible, and fixed whatever breaking changes had been introduced. When run in Visual Studio we see our telemetry in Live Metrics and the logs as expected, but the moment we build this into a docker container and run it form there we lose this telemetry. Exceptions are still logged, however.</p>
  
  <p>We are configuring AI with the following in our <code>startup.cs</code>:</p>
  
  <pre><code>services.AddSingleton(typeof(ITelemetryChannel),
                              new InMemoryChannel() { MaxTelemetryBufferCapacity = 10000 });
  
  services.AddApplicationInsightsTelemetry(new ApplicationInsightsServiceOptions
  {
      EnableAdaptiveSampling = false,
      InstrumentationKey = Configuration.GetValue&lt;string&gt;("ApplicationInsights:InstrumentationKey")
  });
  </code></pre>
  
  <p>I have tried making the buffer larger and smaller, I've downgraded to .Net core 3, I've tried downgrading the <code>Microsoft.ApplicationInsights.AspNetCore</code> package to 2.8.0 (minimum for core 3) since that was what we were using with 2.2 but all to no avail.</p>
  
  <p>I have also looked at what comes out of the container and VS using Fiddler. You can see plenty of chatting to the <code>QuickPulseService</code> (Live Metrics) in both cases, but whereas using VS or the 2.2 version hosted in Docker I can see stuff like this:</p>
  
  <pre><code>"Documents": [
      {
          "Timestamp": "2020-02-13T11:28:17Z",
          "SequenceNumber": 34,    
          "Content": {
              "__type": "TraceTelemetryDocument:#Microsoft.ManagementServices.RealTimeDataProcessing.QuickPulseService",
              "CloudRoleInstance": "XXXXXXXX",
              "DocumentStreamIds": [
                   "all-types-default"
               ],
               "DocumentType": "Trace",
               "Id": "fc840f65-29a8-48dc-a425-e5b7aacd03a5",
               "InternalNodeName": "XXXXXXXX",
               "Message": "Finished processing 159 of 159 events in 3.29 seconds",
               "OperationName": "POST Publish/Publish",
               "Properties": [
                   {
                       "key": "totalEvents",
                       "value": "159"
                   },
                   {
                       "key": "ActionId",
                       "value": "a825bb45-a286-4f85-95f8-64cd88871f8d"
                   },
                   {
                       "key": "RequestPath",
                       "value": "/api/publish"
                   }
               ],
               "SeverityLevel": "Information",
               "Timestamp": {
                   "DateTime": "2020-02-13T11:28:15.309Z",
                   "OffsetMinutes": 0
               },
               "Version": "1.1"
           },
           "Instance": "XXXXXX",
           "DocumentStreamIds": [
               "all-types-default"
           ]
       }]
  </code></pre>
  
  <p>Which is the messages I'm expecting to see in AI, when monitoring the core 3 version in docker the <code>QuickPulseService</code> calls contain no documents at all.</p>
  
  <p>I should not that when running in VS or locally using Docker Desktop we have the logging level set to <code>Debug</code>, the same as we used to with .Net core 2.2.</p>
  
  <p>In case it's relevant, here's the <code>dockerfile</code> as well</p>
  
  <pre><code>FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build-env
  WORKDIR /app
  
  # Copy csproj and restore as distinct layers
  COPY *.csproj ./
  RUN dotnet restore
  
  # Copy everything else and build
  COPY . ./
  RUN dotnet publish -c Release -o out
  
  # Build runtime image
  FROM mcr.microsoft.com/dotnet/core/aspnet:3.0
  
  WORKDIR /app
  
  COPY --from=build-env /app/out .
  
  CMD ["dotnet", "MyApp.dll"]
  </code></pre>
  
  <p>I feel like I must have missed some small piece of crucial configuration but having read the .Net core 3 breaking changes list numerous times I cannot work out what that might be.</p>
  
  <p>Has anyone else experienced this and if so, have you managed to solve the problem? Or do you have any ideas/pointers for me because I am stumped.</p>