azure-webjobs-sdk icon indicating copy to clipboard operation
azure-webjobs-sdk copied to clipboard

Storage queue triggered function generates trace level log entries in app insights

Open mpowney opened this issue 4 years ago • 17 comments

With a queue triggered function in an app, e.g.

        [FunctionName("ProcessRedirectClicksForGeo")]
        public static async void ProcessRedirectClicksForGeo(
            [QueueTrigger(QueueNames.ProcessRedirectClicksForGeo)] string queuedHttpRequestString,
            [Table(TableNames.RedirectSessions)] CloudTable redirectTable,
            ILogger log,
            ExecutionContext context)

And a host.json configuration

        "logLevel": {
            "default": "Information",
        },

Application insights continues to receive the trace level log info about the poll interval of the queue trigger, including messages like:

Poll for function 'ProcessRedirectClicksForGeo' on queue 'processredirectclicksforgeo' with ClientRequestId '3f2a0e15-f014-4537-b0bb-abbc45a4467b' found 0 messages in 3 ms.

and

Function 'ProcessRedirectClicksForGeo' will wait 2000 ms before polling queue 'processredirectclicksforgeo'.

The result is a large amount of data ingested in to application insights, which results in unexpectedly high costs in Azure Monitor.

There doesn't seem to be a clear documented method of preventing these messages from being sent to application insights. Is there somewhere the documentation can be updated to specify how to resolve this?

Side note: when the default setting in logLevel in host.json is set to Information a local dev version of the function app does not produce the trace level logs.

mpowney avatar May 22 '20 21:05 mpowney

The same behaviour can be reproduced by provisioning a Function app via the Azure Portal, using the classic function UI to create a cscript queue triggered function with the boilerplate definition:

run.csx:

using System;

public static void Run(string myQueueItem, ILogger log)
{
    log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
}

function.json

{
  "bindings": [
    {
      "name": "myQueueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "myqueue-items",
      "connection": "AzureWebJobsStorage"
    }
  ],
  "disabled": false
}

host.json

{
  "version": "2.0",
  "logging": {
      "logLevel": {
          "default": "None",
          "Host": "None"
      },
      "applicationInsights": {
          "excludedTypes" : "Dependency;Event",
          "includedTypes" : "PageView;Trace",
          "samplingSettings": {
              "isEnabled": true
          }
      }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[1.*, 2.0.0)"
  }
}

mpowney avatar May 23 '20 02:05 mpowney

Hi @mpowney, Apologies for the delayed response, the issue was somehow lost in the trace. Can you tell us if you are still facing this issue.

v-bbalaiagar avatar Jul 13 '21 13:07 v-bbalaiagar

Seeing the same. My AppInsights log is just full of continuous Queue polling messages -- which makes finding the messages I'm actually interested in very difficult 😞. Please see screenshot below:

image

muj-beg avatar Aug 18 '21 14:08 muj-beg

Looks like this additional logging was in this PR: https://github.com/Azure/azure-webjobs-sdk/pull/2277

muj-beg avatar Aug 18 '21 14:08 muj-beg

Hi @muj-beg, Thank you for your feedback, I shall discuss this internally and get back to you with the findings.

v-bbalaiagar avatar Aug 23 '21 12:08 v-bbalaiagar

@brettsam - can you please take a look. New logs should not be emitted at Info level.

pragnagopa avatar Sep 02 '21 16:09 pragnagopa

@pragnagopa still an issue, application insights traces full of messages related to queue polling. Which logger category (default, Host, Function, ...) is controlling this logger?

otecfuras avatar Dec 03 '21 12:12 otecfuras

These polling logs are logged at level Debug (code here) so if the default log level for your app is set to Information as described in documentation you shouldn't see them.

mathewc avatar Dec 03 '21 16:12 mathewc

@mathewc I know I shouldn't, but they're still logged: image image

otecfuras avatar Dec 03 '21 17:12 otecfuras

This > image < is even more weird, frequency increased to each 2 seconds even I didn't changed that polling interval. It happened after I've overridden level for Function to Information (and restarted function app)> image

otecfuras avatar Dec 03 '21 17:12 otecfuras

The frequency of those polling logs can change, since the poller uses an exponential backoff algorithm, down to the maxPollingInterval you've defined for queues. @brettsam - any ideas on why the AI logger may not be respecting configured log levels?

mathewc avatar Dec 03 '21 19:12 mathewc

I would appreciate any help, I'm billed for unwanted messages and I can't get rid of them. image Actually, _BilledSizes of traces summarized by message for past 30 days show that unwanted messages dominate: image

I'm using .NET Core 3.1, Azure functions v2 and Microsoft.Azure.Webjobs.Extensions.Storage v4.0.3: image

otecfuras avatar Jan 22 '22 00:01 otecfuras

i watching the same logs with the default log level on my function app, im trying to debug a problem where my functions are not executing properly, can this messages be an indication of a problem?

frammnm avatar Feb 09 '22 08:02 frammnm

I had the same problem. Changing the settings as following solved the problem:

{ "Logging": { "LogLevel": { "Default": "Warning" }, "ApplicationInsights": { "LogLevel": { "Azure.Core": "Warning" } } } }

Only wanings will be sent to Application Insights

haronxx avatar Mar 04 '22 09:03 haronxx

@haronxx: Where did you find information on Azure.Core category? LogLevel under ApplicationInsights property isn't even documented property, are you sure this works (for you)?

Fortunately, my problem is gone.

Firstly, unwanted persistence of these messages stopped (few weeks ago) when I changed default logging level to Information:

"logLevel": { "default": "Information", "Function": "Debug" }

Secondly, seeing trace messages in "Live metrics" doesn't mean they are actually persisted in traces table. This was the reason I thought they are still persisted.

Surprisingly, another abusing message type appeared just that day when I changed this setting, it was Executing HttpStatusCodeResult, setting HTTP status code 200 appearing 4 times each 10 seconds (mentioned e.g. here). This was second reason why I thought problem persists because amount (billed size) of messages with empty(operation_Name) didn't decrease (actually this message appears already in screenshot from my post on Jan 22nd). These messages vanished after setting Microsoft.AspNetCore.Mvc.StatusCodeResult logging category to Warning.

Thanks all for help.

otecfuras avatar Mar 13 '22 20:03 otecfuras

Have there been any updates on this? Our logs are littered with this despite having our default logLevel set to Warning

Edit: In my "Log Stream" on the Function App, I still see these messages. However in Application Insights if I query traces, then I don't see them. Maybe I'm misunderstanding something

andy-hugecalf avatar Apr 13 '23 11:04 andy-hugecalf

Any update? We are seeing the same issue

woeterman94 avatar Feb 12 '24 15:02 woeterman94