@JDR Welcome to Microsoft Q&A Forum, Thank you for posting your query here!
I understand that you are having trouble logging DEBUG messages from their Python Azure function to App Insights. You have tried modifying the logging level and host.json file, but the DEBUG logs are still not showing.
I was able to create a simple Python HTTPTrigger function app and deployed it to Azure. I have the below lines of code added in my app:
// Add the import statement
import logging
// Then you can add the below lines in your code.
logging.Logger.root.level = logging.DEBUG
logger = logging.getLogger('MyHttpFunc')
logger.setLevel(logging.DEBUG)
logging.debug('This is a debug log.')
logging.info('This is an info log')
logging.info('Python HTTP Triggered function processed a request.')
I have the below within my host.json:
{
"version": "2.0",
"logging": {
"logLevel": {
"Host.Results": "Error",
"Function": "Debug",
"Host.Aggregator": "Trace"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.*, 4.0.0)"
}
}
While the HTTP Trigger was invoked and executed, I could see the debug statements in the App Insights trace logs:
Also note that for a function app to send data to Application Insights, it needs to know the instrumentation key of an Application Insights resource. The key must be in an app setting named APPINSIGHTS_INSTRUMENTATIONKEY.
Hope this helps.
If you have any follow-up questions, please let me know. I would be happy to help.
**
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.