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:
Related
I'm have built an app that the user save package tracking numbers and then when tapping on them the app sends a request to the parcel provider and gets back the tracking info. Pretty simple.
What i want to do is to create a backend server that stores the user's tracking codes and checks them at regular intervals. When the status change then the user gets a push notification.
My thought is to use a Nodes.js server with a MongoDB database but i'm stuck how to implement the tracking code monitoring on the server. Should i use a timer? Is there a better/simpler approach for this?
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)
I am following this tutorial that creates an Azure Function trigged by http with output to CosmosDB.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-integrate-store-unstructured-data-cosmosdb
When I create just a simple Azure function it works ok, I trigge by http and the http response its ok.
But if create a new output to a ComosDB using the example code indicated in the tutorial the function returns "THIS AZURE FUNCTIONS APP IS DOWN FOR MAINTENANCE"
when trigged.
Please be patience, until last week I was just a c++ programmer hahaha.
My steps:
Creating a CosmosDB account and a database called "testDb".
Creating a Function App:
When trigged using this code its ok.
Creating a CosmosDB output.
I change my code to this:
Now when I trigger by http the response is:
What am I doing wrong?
Grateful.
Someone has reported same issue. To conclude the solution: In portal> Platform features> App Service Editor. Right click on app_offline.htm and delete.
This file is generated to stop the function app when you install cosmosdb extension. It is supposed to be deleted automatically after extension being installed, there seems some problem with this feature, probably related to the slow file system in Consumption plan.
If you are trapped again later, try to turn this behavior off, add an SCM_CREATE_APP_OFFLINE App Setting to your app and set the value to 0, check official announcement for this feature.
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.
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"];