No log stream nor any other std output for my python based function

maliniak 0 Reputation points
2024-03-30T13:17:41.83+00:00

I run a simple azure function in python, with a single REST endpoint.

I can't see logs, just in log analytics, but it's just not convenient enough. App service logs is grayed out, log stream just shows "Connecting to Application Insights...", az webapp log tail results in:

knack.util.CLIError: Failed to connect to 'https://my-function.scm.azurewebsites.net/logstream' with status code '404' and reason 'Not Found'.

I believe that there is nothing outstanding about my host.json file:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

Application Isights seems to be enabled and connected to my function.

Any ideas?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Azar 29,520 Reputation points MVP Volunteer Moderator
    2024-03-30T14:01:06.9433333+00:00

    Hi there maliniak

    That's a good question and thanks for using QandA platform.

    Firstly, make sure that your Azure Function is properly integrated with Application Insights by verifying the configuration in the Azure portal. Double-check the instrumentation key in your local.settings.json file (if applicable) matches the one configured in Azure portal.

    Next, review your Python function code for any potential errors or exceptions that might be causing unexpected behavior.

    Try restarting your Azure Function app to see if it resolves the issue. Sometimes, a simple restart can help refresh the logging and solves this.

    Lastly, if you recently deployed changes to your Azure Function, double-check the deployment to ensure that all necessary files and configurations were deployed successfully without any errors reported in the Azure portal.

    If you cant resolve even after trying all these I suggest you to raise a support request.

    If this helps kindly accept the answer thanks much.


  2. Sina Salam 22,031 Reputation points Volunteer Moderator
    2024-03-30T14:14:06.6166667+00:00

    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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.