azure-functions-python-worker icon indicating copy to clipboard operation
azure-functions-python-worker copied to clipboard

Python Functions do not log Application Insights Exceptions

Open NathanNZ opened this issue 5 years ago • 3 comments

Is your question related to a specific version? If so, please specify:

v3

What language does your question apply to? (e.g. C#, JavaScript, Java, All)

Python 3.8

Question

Out of box the Functions implementation of Application Insights does not raise exceptions using the built in logger eg: logger.error("error:", exec_info=True)

This seems to be resolved by using the "opencensus-ext-azure" library and bolting the AzureLogHandler to the root logger. This then causes trace logs to be printed twice but exceptions show up as expected.

What I'm looking for is a solution to one or the other:

  • Getting exceptions working out of box using Python Functions
  • Disabling Application Insights in the host.json while keeping the "APPLICATIONINSIGHTS_CONNECTION_STRING" convention so I can use conventions while using a library that supports exceptions.

NathanNZ avatar May 05 '20 06:05 NathanNZ

@vrdmr @Hazhzeng Could you provide more insights here, please?

yojagad avatar Jun 25 '20 18:06 yojagad

I believe a recently merged PR to the opencensus-ext-azure module will do this for you, https://github.com/census-instrumentation/opencensus-python/pull/886 It hasn't been pushed to PyPi yet, but we I'll test and reproduce this locally to verify

tonybaloney avatar Apr 22 '21 22:04 tonybaloney

@NathanNZ You can disable all trace capturing (trace == logs) while keeping the connection string by doing something like

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": false,
        "excludedTypes": "Trace"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },
  "extensions": {}
}

This will also disable log capturing from the runtime, not just your application code. More info here https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#applicationinsightssamplingsettings

allenhumphreys avatar Feb 08 '22 17:02 allenhumphreys