Where can I see initialization errors for an Azure Function App?

Reinhart, Jeff (MNIT) 0 Reputation points
2024-12-20T14:26:42.7633333+00:00

I built a Function App using the following tutorial:

https://zcusa.951200.xyz/en-us/azure/azure-functions/create-first-function-vs-code-python

Using V2 and Python 3.11.

I deploy the app via the CLI successfully. I open the Function App in Azure Portal and the http_trigger is listed under Functions. I tested the route and it works.

Then I introduce code that will cause an error on initialization. Immediately after:

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

I introduce a divide by zero error that will run when the function app initializes:

n = 100/0

I deploy the app via the CLI. It says it is successful. I open the Function App in Azure Portal and the http_trigger is no longer listed under Functions. This is the only indication that I can find that there was an error on initialization.

Where can I see what the error is on initialization?

I have tried Log Analytics and Application Insights. From what I can see, these only report on errors post initialization that are triggered when routes are called.

I have checked Function App | Deployment | Deployment Center | Logs. The deployment shows it was successful.

I have tried downloading the *docker.log file from Kudu, but that does not include any errors / tracebacks from the initialization.

Being able to see the error on init is very important for debugging on more complex projects. I have a project that I can run successfully from local, but when it deploys, I get the above behavior. I have isolated which part of the code causes the error by testing when deployments result in an HTTP trigger and when they do not. I need to know what the actual initialization error is from Python to diagnose the cause of the error.

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

2 answers

Sort by: Most helpful
  1. Robina 260 Reputation points
    2024-12-20T15:41:12.7033333+00:00

    Where to Check for Initialization Errors in Azure Function Apps:

    1. Application Insights
    • If Application Insights is configured for your Function App, it can capture exceptions during initialization.
      • Ensure Application Insights is enabled and check the Failures and Search tabs for traces or exceptions during startup.
      Steps to check:
      - Navigate to your Function App in the Azure Portal.
      
         - Go to **Application Insights > Search**.
      
            - Filter logs by **Exceptions** or search for specific terms like "divide by zero."
      
    1. Azure Monitor Logs
    • Use Log Analytics to query the logs from your Function App.
      • A helpful query might look like this:
             traces
             | where message contains "Exception"
             | sort by timestamp desc
        
      This may capture initialization exceptions if the logs are correctly configured. Kudu Diagnostic Console
      - The **Kudu Console** can sometimes provide more detailed logs.
      
         - Access Kudu via `https://<your-function-app-name>.scm.azurewebsites.net/`.
      
            - Check the `LogFiles/Application` folder for detailed error logs.
      
    1. Streaming Logs
      • Use Azure's Live Metrics Stream or stream logs from the CLI to capture runtime and initialization logs.
             
             az webapp 
        
      This can sometimes reveal unfiltered error messages. Function App Configuration
      • Ensure that the AzureWebJobsDashboard and AzureWebJobsStorage connection strings are configured correctly. Missing or incorrect values can lead to initialization issues.
    2. Inspect Docker Logs (For Linux Containers or Custom Images)
      • If your Function App is running in a container, initialization errors may be in the container logs.
      • Download the container logs using:
             az webapp log download --name <function-app-name> --resource-group <resource-group-name>
             
             
        
      • Look for docker.log and other files in the zip archive.
    3. Enable Detailed Logs
      • Modify your host.json file to include detailed logging:
             
        

    { "logging": { "logLevel": { "default": "Information", "Function": "Trace" } } } ```

    • Redeploy your Function App, and recheck the logs.

    Why the http_trigger Disappears:

    When an initialization error occurs, the Function App fails to fully load. The absence of the http_trigger in the portal indicates that the app's startup process was interrupted. The error, in this case, prevents the Function App from registering the function.


  2. Pinaki Ghatak 5,310 Reputation points Microsoft Employee
    2024-12-23T12:22:51.9633333+00:00

    Hello @Reinhart, Jeff (MNIT)

    To find the error that occurred during initialization, you can try checking the Function App's logs in Kudu. Here are the steps to do that:

    1. Go to your Function App in the Azure Portal.
    2. Click on "Platform features" in the left-hand menu.
    3. Under "Development Tools", click on "Advanced tools (Kudu)".
    4. In the Kudu dashboard, click on "Debug console" and select "CMD".
    5. Navigate to the "LogFiles" folder and then to the "Application" folder.
    6. Look for the log file with the most recent timestamp and open it.
    7. Search for any error messages or stack traces that occurred during the initialization of your Function App.

    If you still cannot find the error, you can try adding more detailed logging to your code to help diagnose the issue. You can use the logging module in Python to log messages at different levels of severity. For example, you can add a logging.error() statement to log any errors that occur during initialization.


    I hope this helps you find the error and diagnose the issue with your Function App. I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.


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.