Hello maliniak,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you are experiencing difficulties in monitoring and troubleshooting your Python-based Azure Function due to the absence of log output and inability to access log streams or App Service logs.
To solve this incident, let's try the followings:
First, check Logging Configuration: Ensure that your Azure Function's host.json file is configured correctly to enable logging to Application Insights. Refer to the provided host.json snippet and verify that logging to Application Insights is enabled and properly configured. Here below is an example of a host.json file snippet with logging configuration for enabling logging to Application Insights:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
In the above snippet:
"version": "2.0" specifies the version of the host.json schema. "logging" section configures logging settings for the Azure Function. "applicationInsights" is a sub-section specifying that logs should be sent to Application Insights. "samplingSettings" allow you to configure sampling of log data. In this example, sampling is enabled ("isEnabled": true) and excludes logging of request types ("excludedTypes": "Request").
Secondly, make sure your Python function code includes appropriate logging statements using the logging module. For example:
import logging
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Function execution started.')
# Your function logic here
logging.info('Function execution completed.')
return func.HttpResponse("Function executed successfully.")
Thirdly, double-check that your Application Insights resource is properly connected to your function app. You can verify this in the Azure portal under the Application Insights settings.
Finally, ensure that your function app is hosted on an appropriate App Service Plan that supports logging features. Check if the App Service Plan is set up correctly and has the necessary permissions to enable logging. Also, role assignments for your Azure subscription or resource group needs to be checked to ensure that you have the necessary permissions to access App Service logs. You might need the appropriate roles such as Owner, Contributor, or Reader.
You can read more additional resources from the right side of this page.
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
Please remember to "Accept Answer" if answer helped, so that others in the community facing similar issues can easily find the solution.
Best Regards,
Sina Salam