Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure function verbose trace logging to Application Insights

I have an Azure function that's connected to an App Insights instance. The function app emits log messages which I can see in the log stream in the Azure portal, and as App Insights traces.

I've increased the console log level to Verbose by adding a "tracing" element to host.json (https://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json), so Verbose level messages show up in the log stream (in both the function page in the Azure portal, and in Kudu), but I can't get Verbose level traces to appear in App Insights.

Does anyone know how to get App Insights to show Verbose level traces from an Azure Function? Is it even possible? (Info traces and above are showing up just fine in App Insights)

like image 474
tones Avatar asked Sep 13 '17 02:09

tones


1 Answers

You have a lot of control over your log levels for App Insights in Functions, but you don't use the tracing element for these. We're working on pulling the docs together in one cohesive location, but here's some links that can help:

  • The new logger.categoryLevel host.json settings: https://github.com/Azure/Azure-Functions/wiki/App-Insights-(Preview)#hostjson-settings
  • The WebJobs documentation, which gives a bit more detail on how the category filter works (behind the scenes, the host.json settings are serialized into this): https://github.com/Azure/azure-webjobs-sdk/wiki/Application-Insights-Integration#filtering

For your specific example, you can open up all the Debug logs (which matches Verbose in TraceWriter) with this in your host.json:

{
  "logger": {
    "categoryFilter": {
      "defaultLevel": "Debug"     
    }
  }
}

If you just want to see the verbose logs coming from your Function itself (i.e. you don't want the host's verbose logs appearing), you can restrict that with this -- which says 'for logs with the "Function" category (which is the category that function logs use), show me everything with Debug or higher log level':

{
  "logger": {
    "categoryFilter": {
      "categoryLevels": {
        "Function": "Debug"
      }
    }
  }
}
like image 58
brettsam Avatar answered Jan 27 '23 03:01

brettsam