Azure-functions-host: AppInsights loglevel problems (requests and/or traces)

Created on 27 Jan 2020  路  14Comments  路  Source: Azure/azure-functions-host

Functions Version 3
Application Insights 2.10.0

I'm trying to understand how logsettings work.
I would like function invocation to be logged as a requests, but turn off tracing.
From what I have tested it seems that loglevel needs to be set to Information for the request logging to work, but that will also enable all tracing, which will be a lot of not needed data.

Is there a way to configure appinsights logging to log requests but not traces ?

Needs

All 14 comments

@brettsam, do you know if this is possible today?

I know we have options to disable live metrics, dependency tracking and perf counters. But do we allows disabling TraceTelemetry?

Results are logged with a category of Host.Results (see here). So, you can set a default log level of None, but then set Host.Results to Information. That will cause everything but the results to be ignored. I just gave this a try and it looks like it gives you what you're looking for.

{
  "version": "2.0",
  "logging": {
    "logLevel": {
      "default": "None",
      "Host.Results": "Information"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": false
      }
    }
  }
}

Thanks Brett! @cannehag, please let us know if that works for you.

Thank you @ankitkumarr & @brettsam, this seems to work fine. But it seems to also have an effect on the dependency logging which I still would like to use. Is there a way to keep that ?

I really would like all the logging (request, exceptions, dependencies, customevents, perf counters etc), but NOT the traces.

Any updates on this one?

I just tried this again using:
Azure Functions Core Tools (3.0.2245 Commit hash: 1d094e2f3ef79b9a478a1621ea7ec3f93ac1910d)
Function Runtime Version: 3.0.13139.0

My host.json:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": false
       }
    },
    "logLevel": {
       "default": "Warning",
       "Host.Results": "Information"
    }
  }
}

When looking at appinsights, now I only get traces but NO requests. Shouldn't it be the opposite ?
@brettsam @ankitkumarr

I just tried this locally with your exact host.json and all of my requests are correctly written to App Insights.

A couple things to double-check:

  1. That you have APPINSIGHTS_INSTRUMENTATIONKEY set in your local.settings.json (I assume you do if you see traces)
  2. That you wait a bit for the telemetry to flush. If you kill the process too quickly you may miss them and unless you exit gracefully (I believe ctrl+c will do this) the in-memory logs won't have flushed yet.
  3. You wait ~5 minutes for the logs to show in App Insights.

When digging deeper into our code we have some custom ITelemetryInitializer's that modified some properties on the Telemetry.
We also have a function that removes some customDimensions because we thought it wasn't necessary to log that much information.
Here I might have found the reason and I think it is because we remove the "Category" dimension. Do you know if that one needs to be there for the request logging to work @brettsam ?

Category is required as all filtering is done on Category (for example -- Host.Results is a category, which is how the filtering knows whether to include it or not).

Thank @brettsam. Is there any other customDimensions that are required that you know of? Otherwise I would consider this working now!

One follow up question though @brettsam. Do you know if it is possible to wildcard the logsettings.
Traces are logged with category set to "Function.[FunctionName]" and my trace logs have the category "Function.[FunctionName].User".

Is it possible to configure this so that only my custom logs are actually saved. Like this:

"logLevel": {
"default": "Warning",
"Function.*.User": "Information",
"Host.Results": "Information"
}

@brettsam Any information we need to provide further.

Unfortunately, wildcards are not supported -- we rely on the default .NET Core log filtering (https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1#how-filtering-rules-are-applied) which takes the longest match.

@cannehag hope the above explanation answered your question.Proceeding to close the issue ,please feel free to get back to us if you have any queries further.Thank You!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yvele picture yvele  路  3Comments

christopheranderson picture christopheranderson  路  4Comments

paulbatum picture paulbatum  路  4Comments

krillehbg picture krillehbg  路  3Comments

helgemahrt picture helgemahrt  路  4Comments