2

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.

scantrell
  • 111
  • 1
  • 6
  • 1
    Maybe results are filtered out due to sampling? You can exclude events manually, see [the docs](https://learn.microsoft.com/en-us/azure/azure-functions/functions-monitoring?tabs=cmd#configure-sampling) – Peter Bons Apr 02 '20 at 12:14
  • 1
    I don't have a definitive answer, but I would suggest setting a TelemetryClient as a static member variable instead of recreating a new one for each request. You are generating a lot of outbound connections from your Function in a high volume situation, and those outbound connections are finite. – Rob Reagan Apr 02 '20 at 14:26

1 Answers1

1

Please disable sampling in host.json:

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

applicationInsights.samplingSettings
Sampling in Application Insights

Markus Meyer
  • 3,327
  • 10
  • 22
  • 35