Azure Function Context Log Location - node.js

How do you view the context.log messages for an Azure Node.js Function?
If I have the following:
exports.handler = async (context) => {
context.log.info('Hello Bob');
};
Where would I go to see Hello Bob?
I know exactly how to view such a phrase in AWS Cloudwatch but I cannot find the same in Azure. I have looked at: https://learn.microsoft.com/en-us/azure/azure-functions/functions-monitoring but it points to Application Insights which when I go there and look at say, Activity Logs, there is no information. I have also looked at Logs on that screen but it wants to run queries. So, how do you look at context.log.info data within Azure?

You can access that in the Azure Portal
It does not appear immediately. may take a couple of minutes after you run your function. also make sure the function has started
Locate your Function app and click "Functions" > "your function name" > "Monitor" and any of the log records:
Or you can use the insights for that:
and

Related

Alert when Azure function fails to initialize

I have an Azure function, which fails while running Startup.cs (while initializing the runtime) because it can't load a key from a Key vault. I would like to automate the deployment of this function in the future and therefore I would like to set up an alert to trigger if the function can't initialize correctly for any reason. (I can fix this speficic error, I just use it as an example).
At the moment I see the error in the Notifications section of the function page in the Azure portal:
I also see the exceptions in Diagnose and solve problems -> Availability and Performance:
But I can't seem to find a way to set up an alert to respond to this situation. I assumed that Resource health alert would cover this, but it doesn't. Maybe because to portal reports the function as Status: Running. I also can't find this error in Application Insights.
Is there any way to set up this alert?
To create the Alerts for Function App Runtime failures, start with the Alert Action Groups.
Open your function app in the Azure Portal and create the action group that points to your function and email configuration:
In the same function app menu > Logs > Get the Function Request Failure results such as below:
Then, click on “New Alert Rule” > Insert the values for Alert logic such as Frequency of Evaluation, Operator, Threshold Value, Measure of data summary, etc.,
Next, Select the Action Group which is created at the starting - that contains the Selected Function Data and the Email Notification configuration details:
After configuring the alert group, you’ll get the mail that the alerts are mailed accordingly:
I have given the wrong input to get the alert for the Function Runtime failure, which is driven to the Alerts:
Result:
For more details regarding Azure Alerts, refer to this MS Doc.
Updated Answer:
- This query gives the function errors messages in the logs and from this panel we can create the alert rule for the errors and warnings.

Lookup Azure application name from within a running function app

Is it possible to lookup the application name for an Azure app as it runs, i.e., get the information about that is displayed in the Azure portal? In the example below, I'd want something to tell me from within the application that I am running sitemap-prod-eastus.
I've been looking at the Azure Context object but not seeing what I need. There is an invocation ID, a name for the function, a directory - not the info in this window.
Maybe this can be done through Azure Application Insights?
I am working in Node JS.
I've not seen anything that would expose this to a function app. That said, there is one sort of workaround that you could do which would work - go to the Configuration blade for the function app, Application settings tab, and add a configuration key like function_name and set its value to the name of your app. Your app could then just read it out of configuration.
It's an extra step, but if you're doing it with something like ARM or Terraform, it's just another configuration entry with a variable you already declared to set up the app in the first place.
Answering my own question: Azure provides WEBSITE_SITE_NAME in the runtime environment that matches the name of the function app.

How to know Azure Function is restarted?

I have noticed of my Azure Queue has triggered and after 8 minutes the same queue has started again with the same queue message as per my app insight logs.
Where I can find the Azure logs for queue triggered or function have restarted or function has failed? I have read one of those articles Azure dependencies where they have explains dependencies.
Thank you in advance.
If you have configured Diagnostic Settings for your function then you can query the Log analytics workspace ( usign Kusto query) for FunctionAppLogs like below. The field "Message" contains the reason why the fucntion was executed. For e.g if the function was executed via an API call then you would see something like "Reason=This function was programmatically called via the host APIs". You can search for specific words in the message. Also there is a Level field ( like Information, Warning,Error) on which you can filter. Here is the relevant docs from Azure.
FunctionAppLogs
| where Message contains "ServiceBus"

I get 429 status code for microsoft.web/serverFarms when I create function App on azure

I have azure functions developed in node js. When I create a cloud instance for function app, it gets stuck on deployment process with all the resources OK status. Microsoft.Web/serverfarms returning 429. The error message reads as:
**"status"**: "Failed",
**"error"**: {
**"code"**: "429",
**"message"**: "App Service Plan Create operation is throttled for subscription <subcription_id>. Please contact support if issue persists.",
}
Please let me know what the possible solution will be for this
Turns out, you just need to create a new function application with different server location. and delete all the related instances of the previously deployed azure function.

Best way to log app data from a console app running inside a container on ACI

A seeming simple ask, but had no luck finding the best way.
So i need to log application events from a console app that will spin up inside a container and do some work then die.
How can i log custom data from inside?
I've tried Azure Monitor and created a workspace and used HTTP Data Collector API inside the app but no joy in working out where logs are being stored.
Is there a simple way to log to an Azure Storage account and then using Azure Monitor to manage the events?
I've been googling for hours but a lot of posts are 8 years old and not relevant and i cannot really find a simple use case in modern azure.
Perhaps it's so simple i just cannot see it
Any pointers or links greatly received!
thanks
Paul
Why not trace events using Application Insight custom events ?
https://learn.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics
With that you can trace events with any metadata and check them in the Azure Application Insights Blade or reach them by the Application Insights SDK or The Api.
You just need to create an Application Insight instance and use the Telemetry Key to do that.
SDK: https://github.com/Microsoft/ApplicationInsights-dotnet
API : https://dev.applicationinsights.io/reference
Code sample to write events:
TelemetryClient client = new TelemetryClient();
client .InstrumentationKey = "INSERT YOUR KEY";
client.TrackEvent("SomethingInterestingHappened");
Also you can send more than just an string value:
tc.TrackEvent("PurchaseOrderSubmitted",
new Dictionary<string, string>()
{
{"CouponCode", "JULY2015" }
}, new Dictionary<string, double>()
{
{"OrderTotal", 68.99 },
{"ItemsOrdered", 5}
});

Resources