Azure Functions, NodeJS and Application Insights - node.js

I have written some simple functions and enabled Application Insights,
Its all showing as connected and I can see that's its tracking http statues, eg I get a failed request count and server response times etc.
I understand that I can add application insights to node with the following code
let appInsights = require("applicationinsights");
appInsights.setup("[your ikey]").start();
But I was hoping it would just work without this, I can see that the function is outputting logs when I use the log stream
But when I use app insights I don't see anything in any of the log tables
Do I need to add insights via code to my function or I am missing some secret config option.

That's also a good idea to add application insights module into your node project to achieve monitor feature for your function. Both code and codeless are good choices.
In my opinion, the biggest difference between code and codeless monitor is the custom telemetry data. But I think in most scenarios, default information collected is enough for daily using, official doc says:
Application Insights collects log, performance, and error data, and
automatically detects performance anomalies.
So I think it's ok for you when you could get traces and error messages after adding appinsights module and recreate a new appinsights instance. And you can also try to use codeless configuration I mentioned in the comment(azure portal-> your function written by nodejs-> Application insights-> enable-> create new resource)

Related

Getting "BlockCountExceedsLimit" exception while using log4net.Appender.AzureAppendBlobAppender

I'm using log4net.Appender.AzureAppendBlobAppender to log my web app's info & errors. Sometimes I'm getting the "BlockCountExceedsLimit" exception. It is due to the append blob accepts only 50,000 block commits after that it through the exception (Conflict (409)). I have checked the code and found that it waits for the 512 log events and flush each log entry separately to the append blob. So, we can log only 50,000 log entries in a day.
Can anyone please help me on this? Does anyone know any alternate for this?
Thanks,
Karthik
According to your description, I assumed that you are using log4net.Appender.Azure nuget package. As you can see under AzureAppendBlobAppender.cs:
private static string Filename(string directoryName)
{
return string.Format("{0}/{1}.entry.log.xml",
directoryName,
DateTime.Today.ToString("yyyy_MM_dd",
DateTimeFormatInfo.InvariantInfo));
}
Per my understanding, you could follow AzureAppendBlobAppender.cs to write your custom AzureAppendBlobAppender and adjust the Filename,SendBuffer methods to meet your requirement.
I'm using log4net.Appender.AzureAppendBlobAppender to log my web app's info & errors.
Since you use azure web app to host your application, you could use the built-in Application Logging (Blob), and azure side would help you generate the logs hourly. You could log into Azure Portal, choose your web app, enable application logging (Blob), set the logging level to Information, details you could follow Enable diagnostics logging for web apps in Azure App Service.
For your application, you could use the following code to log info and errors.
System.Diagnostics.Trace.TraceError("xxxxx");
System.Diagnostics.Trace.TraceInformation("xxxxx");
I've changed the code to a little bit to append the blob, once the buffer reaches the threshold value (512 log entries) it'll flush the log entries in single commit.

Application Insights does not log successful requests

I have added Azure Application Insights to a number of my .Net WebAPI applications. I've noticed that I do not receive successful request telemetry from these applications. I do receive dependency telemetry and failed requests but not the actual telemetry that the request has been made. By fudging the URL or the request and forcing a failure, I can see that get sent to AI, so my issue is definitely not with the instrumentation key.
I initialize the instrumentation key as follows:
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey =
ConfigurationManager.AppSettings["ApplicationInsightsKey"];
I have attempted to remove AI from the application entirely and added it again using the Configure Application Insights option but it still does not work. There is another of my web apps that uses AI that was configured a while back and it works perfectly, I have replaced the set up of the broken app with that of the working app and also made the package versions line up but I still only get telemetry for failed requests. The capture below from the Live Stream shows this, the red arrow points to the dependency calls made for the successful request, yet nothing shows in the Request Rate graph for it. In contrast there is a failure before it, and that is logged.
I just found the answer for this in a solved issue on the Application Insights Github. The solution is to open your ApplicationInsights.config and scroll to the telemetry module Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule below it comment out the line System.Web.Handlers.TransferRequestHandler
This issue has been fixed and is due to go out in version 2.5 of the packages. You can read through the issue here https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/175
Try below one, it works for me:
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration configuration = Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.CreateDefault();
configuration.InstrumentationKey = System.Web.Configuration.WebConfigurationManager.AppSettings["InstrumentationKey"];

Tracing in Azure Web App - nothing being logged in the LogFiles/Application

This is a similar post to Azure Web App Trace logs not appearing in log, however the original poster seems to have abandoned the question without resolving/accepting an answer.
I am trying to trace an issue that only happens on the Azure web app (now called app service). I'm unable to perform any remote debugging due to our company policies, so tracing is our best tool.
However, I've tried following various tutorials, but I still can't seem to get any of my trace information logged.
I've tried:
Setting the Application Logging (Filesystem) Level to Verbose, Information, Error -- nothing.
Looking for the logs in
the FTP server at /LogFiles/Application
the KUDU interface at https://.scm.azurewebsites.net and again, navigated to /LogFiles/Application
portal's Monitoring > Live stream (the section under Diagnostic Logs for the website)
Nada. I've even waited a few hours (thinking it might be a delay), and still nothing.
I setup a very basic hello world ASPX and all it does (in the Page_Load) is try to write 'hello' to the trace log using
Trace.TraceError
Trace.TraceInformation
Trace.TraceWarning
Trace.WriteLine
Console.Out.WriteLine
Console.Error.WriteLine
Some weird stuff I've also tried
setting my debug=true in my web.config
setting CustomErrors from RemoteOnly to Off
trying to use System.Diagnostics.TextWriterTraceListener
Anyone have any ideas I might try?
Exceptions in your live web app are reported by Application Insights. You can correlate failed requests with exceptions and other events at both the client and server, so that you can quickly diagnose the causes. You may refer this article: https://learn.microsoft.com/en-us/azure/application-insights/app-insights-asp-net-exceptions.
If you use NLog, log4Net or System.Diagnostics.Trace for diagnostic tracing in your ASP.NET application, you can have your logs sent to Azure Application Insights, where you can explore and search them. Your logs will be merged with the other telemetry coming from your application, so that you can identify the traces associated with servicing each user request, and correlate them with other events and exception reports. You may refer this article: https://learn.microsoft.com/en-us/azure/application-insights/app-insights-asp-net-trace-logs.

How can I set the Application Version number in Azure Application Insights for User and Exception data?

I've been working on getting some basic metrics setup within Azure Application Insights. In the Website and the API I am setting the application version using a TelemetryInitializer and am able to filter by this for Server Requests:
telemetry.Context.Component.Version = "1.0";
When I try to filter or group by Application Version for other types of requests (for example, Users or Exceptions), it shows up as undefined. Does anyone know how to make this kind of filtering work?
Here's what I see in the metrics explorer (ignore all of the undefined requests on the server requests, as they were from before the version was set, and some of the other APIs).
[
telemetry.Context.Component.Version = "1.0";
should totally work, and it looks like it is for the requests.
couple things i can think of:
the exceptions are browser (javascript) exceptions, not server exceptions, so they're not getting your context.
the exceptions are occurring either
a. before you're setting the version on the context, or
b. are happening on another telemetry context, that doesn't have your version set?

How to stop collecting telemetry once started in Windows Store app?

I've started looking at adding Azure Application Insights to my app. The documentation and the SDK seems to be a bit sparse ...
I've added a call to Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync and the data is being successfully reported to the Azure Portal.
However, I want to provide a setting in the app so that the user can turn collection on and off. Is there a way of stopping collection or can I only "not start" collection? In other words, if the user changes the setting value, can I react to it straight away or just when the app starts up?
Thanks.
I have done this:
To dynamically stop and start the collection and transmission of telemetry:
using Microsoft.ApplicationInsights.Extensibility;
TelemetryConfiguration.Active.DisableTelemetry = true;
To disable selected standard collectors - for example,
performance counters
HTTP requests
dependencies
Delete or comment out the relevant lines in ApplicationInsights.config. You could do this, for example, if you want to send your own TrackRequest data.
Taken from App Insights Documentation:

Resources