Python Functions do not log Application Insights Exceptions
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.
@vrdmr @Hazhzeng Could you provide more insights here, please?
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
@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