Search code examples
pythonloggingazure-functionsazure-web-app-serviceazure-application-insights

Azure Function : How do I write my logs to Azure Application Insights using local debug mode with Azure Functions using Python?


I want to write my logs to the Azure Application Insights but I do not know how to achieve it.
Do I need to update my azure function local.settings.json and host.json file ??
Also, do I need to use call specific function in init.py file to write my logs to Azure Application Insights?
Can you please share some examples to write logs. Please note- I am using python for my Azure function.
Thanks


Solution

  • This is the host.json:

    {
        "version": "2.0",
        "logging": {
            "applicationInsights": {
                "samplingSettings": {
                    "isEnabled": true,
                    "excludedTypes": "Request"
                }
            }
        }
    }
    

    This is the official settings:

    https://learn.microsoft.com/en-us/azure/azure-functions/functions-host-json#applicationinsights

    'applicationInsights.samplingSettings.isEnabled' is to Enables or disables sampling.