Application logging for Azure Functions in Python

AJG 436 Reputation points
2020-07-13T11:49:37.917+00:00

How do you enable application logging for (serverless) function apps that have been deployed to Azure - written in Python (using VS Code).

For example, this line appears in the example code:

logging.info('Python HTTP trigger function processed a request.')

how do you get that message to appear, specifically in the Monitoring -> Log Stream console ?

Various posts say this is done by changing settings in Monitoring -> App Service Logs - but this is greyed out and disabled in the Azure web console.

A

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,803 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,263 questions
0 comments No comments
{count} vote

Accepted answer
  1. AJG 436 Reputation points
    2020-07-14T16:27:25.61+00:00

    Rather than try to untangle how all this works - the solution that I opted for was to create a LogHandler that writes messsages to a Cosmos DB container - which can then be streamed to a console in almost real time - and where the log level can be set dynamically at both ends - it took me much less time to implement that - which is simple, and works perfectly - than try to understand the Azure documentation.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Krish G 2,326 Reputation points
    2020-07-13T14:19:44.943+00:00

    You need to enable Application Insights integration for your function app. If not done during app creation, you can setup later by following this.


  2. AJG 436 Reputation points
    2020-07-13T18:20:03.013+00:00

    Hello,

    I have had a look at these links.

    As far as I can tell, this does not fix the 'App Service Logs" menu item being disabled - rather this appears to be some alternate mechanism which uses 'Application Insights'- but it is not very clear.

    Either way, running through these steps does not seem to re-enable that menu item - which according to 'what it says on the tin' - is obviously the correct place to look - in order to configure app tracing.

    You sent two links, both to sections in:

    From this document:

    "Early versions of Functions used built-in monitoring, which is no longer recommended. When enabling Application Insights integration for such a function app, you must also disable built-in logging."

    Reading further - the justification for this appears to be that 'built in logging' which uses Azure Storage may not cope with high throughput situations. This raises several issues:

      • What I want is to see near real time application log data in the Monitoring -> Log Stream Window, as per my original question - throughput considerations do not really matter at this stage, so - can application insights stream near real time application log information to function app -> Monitoring -> Log Stream for a Python function app ?
    1. why implement the in the first approach first place, surely the whole point is that this storage is supposed to handle high throughput in a robust fashion.

    then, from the linked document: "When you enable Application Insights, disable the built-in logging that uses Azure Storage"
    does this therefore imply that the storage account which is set up to support the azure functions, when they are created is no longer required once you install the insights ? is this automatically removed?

    In the document, step 4:

    1. The exporter sends log data to Azure Monitor. You can find the data under traces.

    Which is not very specific - if we assume reasonably - that this means look for a menu item called 'traces' under Monitoring - well, there isn't one. there is something under Developer -> Monitor -> Invocation Traces - but these are not streamed, and do not seem to include app logging.

    There is also some suggestion that the log level needs to be adjusted. Clearly it cannot be correct that this should be done in the code to be deployed - because the need to set tracing level cannot be anticipated before deployment, so this must be dynamically configurable on the 'server side'.

    In this document, under "Disable Built In Logging", there is a link to: "How To Manage A Function App"

    https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings#settings

    this states: "to disable built-in logging, delete the AzureWebJobsDashboard app setting"

    My understanding is that app settings etc apply to .Net projects in Visual Studio - not a Python projects in VS Code - so this does not seem very relevant.

    Moving on to the 'Streaming Logs' section in "Monitor Azure Functions" , here there are two options:
    1.- Built in log streaming
    2.- Live Metrics Stream

    My understanding from your reply is that it is necessary to use the second option, because that uses 'application insights', however, if I follow the link from here to 'Live Metrics Stream', then this says:

    "Live Metrics are currently supported for ASP.NET, ASP.NET Core, Azure Functions, Java, and Node.js apps" - from this it is not very clear whether this is expected to work with Azure Functions implemented in Python, or not.

    However, if we assume it is supposed to work, then if I go to my function app -> Investigate -> Live Metrics

    what I see is a screen with "Demo" written across it, and the message: "Not available: your app is offline or using an older SDK"

    • However, the app is online, and using the software installed by following the instructions in the documentation.

    If I search elsewhere for the log messages that I am looking for:

    At this stage it is hard to proceed - because the screenshots in the documentation look nothing at all like the current version of the Azure portal - but they suggest that logging might be hidden somewhere inside metrics - so looking here,:

    • in Monitoring -> metrics - no obvious log output
    • in Monitoring -> logs - a more obvious choice - but this appears to be a misnomer - possibly derived stats from logs, but not raw logs

    in Monitoring -> Log Stream - no application log output

    So I have had no luck in making any of this work so far.

    A

    0 comments No comments