3
votes

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.

We are configuring AI with the following in our startup.cs:

services.AddSingleton(typeof(ITelemetryChannel),
                            new InMemoryChannel() { MaxTelemetryBufferCapacity = 10000 });

services.AddApplicationInsightsTelemetry(new ApplicationInsightsServiceOptions
{
    EnableAdaptiveSampling = false,
    InstrumentationKey = Configuration.GetValue<string>("ApplicationInsights:InstrumentationKey")
});

I have tried making the buffer larger and smaller, I've downgraded to .Net core 3, I've tried downgrading the Microsoft.ApplicationInsights.AspNetCore package to 2.8.0 (minimum for core 3) since that was what we were using with 2.2 but all to no avail.

I have also looked at what comes out of the container and VS using Fiddler. You can see plenty of chatting to the QuickPulseService (Live Metrics) in both cases, but whereas using VS or the 2.2 version hosted in Docker I can see stuff like this:

"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"
         ]
     }]

Which is the messages I'm expecting to see in AI, when monitoring the core 3 version in docker the QuickPulseService calls contain no documents at all.

I should not that when running in VS or locally using Docker Desktop we have the logging level set to Debug, the same as we used to with .Net core 2.2.

In case it's relevant, here's the dockerfile as well

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"]

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.

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.

1

1 Answers

0
votes

I recently ran into this problem when updating our .NET Core 2.2 Web API to 3.1. At the same time, I upgraded all of the supporting libraries, including Microsoft.ApplicationInsights.AspNetCore, upgrading it from 2.12.1 to 2.14.0. After I did that, I stopped getting SQL statements in Application Insights. When I downgraded Microsoft.ApplicationInsights.AspNetCore back to 2.12.1 (but keeping everything else the same), SQL statements appeared again in Application Insights.