Application insights for function app not showing console logs

Kallol Borah 0 Reputation points
2023-06-08T06:19:35.5266667+00:00

Hello

I am writing to figure out why application insights for function apps are not showing any console log statements in the function app's code ?

I only see something of the sort below.

2023-06-08T06:07:53Z [Information] Executing 'Functions.approval' (Reason='This function was programmatically called via the host APIs.', Id=9a3eeb87-8f4a-4a17-84c6-9e8e5f51312b)
2023-06-08T06:07:53Z [Verbose] Sending invocation id: '9a3eeb87-8f4a-4a17-84c6-9e8e5f51312b
2023-06-08T06:07:53Z [Verbose] Posting invocation id:9a3eeb87-8f4a-4a17-84c6-9e8e5f51312b on workerId:73437135-3a89-4520-91cb-16aee813ae4b
2023-06-08T06:08:14Z [Information] Executed 'Functions.approval' (Succeeded, Id=9a3eeb87-8f4a-4a17-84c6-9e8e5f51312b, Duration=21110ms)
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,029 questions
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 24,795 Reputation points Microsoft Employee
    2023-06-08T10:53:23.3433333+00:00

    @Kallol Borah Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    Looking at the issue verbatim you have posted, I see that your console log statements are not being logged in the Application Insight logs.

    When you write traces (ILogger log) from your application code, you should assign a log level to the traces. Log levels provide a way for you to limit the amount of data that is collected from your traces.

    A log level is assigned to every log.

    Trace 0 Logs that contain the most detailed messages. These messages might contain sensitive application data. These messages are disabled by default and should never be enabled in a production environment.
    Debug 1 Logs that are used for interactive investigation during development. These logs should primarily contain information useful for debugging and have no long-term value.
    Information 2 Logs that track the general flow of the application. These logs should have long-term value.
    Warning 3 Logs that highlight an abnormal or unexpected event in the application flow, but don't otherwise cause the application execution to stop.
    Error 4 Logs that highlight when the current flow of execution is stopped because of a failure. These errors should indicate a failure in the current activity, not an application-wide failure.
    Critical 5 Logs that describe an unrecoverable application or system crash, or a catastrophic failure that requires immediate attention.
    None 6 Disables logging for the specified category.

    This logLevel is defined in the host.json. So please check within your host.json file which logLevel has been defined.

    I have tried to reproduce the issue at my end with ILogger log information statement and I see that the logging (log) information is appearing in the Application Insight logs.
    User's image

    I hope you have tried checking in the right AppInsights logs.

    Please check the Log Stream section within the Function App resource blade and select the App Insights Logs and you can try to reproduce the issue and check if it gets logged.
    User's image

    You can navigate to the concerned Function within your FunctionApp and Monitor section and Click on Run query in Application Insights.
    User's image

    You can then run the below query to get the trace log Information:

    traces 
    | where message contains "log"
    | where timestamp > ago(30m) 
    | project timestamp, customDimensions["InvocationId"], message
    | order by timestamp
    

    User's image

    If you have the right logLevel setting in the host.json file you should be able to see it as shown above.

    Hope this helps.

    Sharing a few relevant articles:
    https://learn.microsoft.com/en-us/azure/azure-functions/configure-monitoring?tabs=v2
    https://learn.microsoft.com/en-us/azure/azure-functions/functions-monitoring
    https://learn.microsoft.com/en-us/azure/azure-functions/analyze-telemetry-data

    **
    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    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.