Search code examples
azurefunctionappinsights

Azure Functions missing rows in AppInsights


I need to log information from all invocations, successful or not, of a function app in Azure. I first tried just using log.LogInformation() and found that messages were not being written from all function invocations. Doing some research I got to understand that in high load scenarios (mine is a high load scenario), sometimes the runtime decides not to log some of the successful invocations. Fair enough.

I then tried using custom events to do logging and capture the info I needed:

                    TelemetryConfiguration config = TelemetryConfiguration.CreateDefault();
                    TelemetryClient tc = new TelemetryClient(config);
                    Dictionary<string, string> props = new Dictionary<string, string>();
                    props["msgid"] = msgid;
                    tc.TrackEvent("MsgToBenefitsService", props);

Still no luck, in some runs I did, I saw only 82 rows in app insights from 1000 invocations. I haven't been able to find any documentation saying that Custom Events might not be logged, so I expected that I would see 1000 events logged for 1000 invocations.

Is there anything wrong with the logging code above ? And are there any options to guarantee that I can write information from an invocation to AppInsights ? Or am I stuck with having to explicitly log myself from the function app ?

As background, this function app has a service bus trigger to read messages off a topic. I'm using v3 of the runtime.

Any help would be appreciated.

Thanks.


Solution

  • Please disable sampling in host.json:

    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": false
      }
    }
    

    applicationInsights.samplingSettings
    Sampling in Application Insights