Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for an Azure Application Insights Alert to trigger another function?

I would like to use Application Insights to monitor a Logic App that chains several Azure Functions. I want the chain to be as safe as possible, and i if something goes wrong i want to have the http request that failed to be processed correctly by the functions. I figured i could raise alerts from Application Insights when something goes wrong, however i'm not sure how to get the message that failed into a blob or a "failed message queue".

Is it possible for an Application Insights Alert to be a trigger for a function that would add data to a blob?

like image 408
Kuczi Avatar asked Jun 08 '18 07:06

Kuczi


People also ask

How does Azure function connect to application insights?

In your function app, select Configuration under Settings, and then select Application settings. If you see a setting named APPINSIGHTS_INSTRUMENTATIONKEY , Application Insights integration is enabled for your function app running in Azure.

What are the different stages of alerts available in app insights?

At the moment, there are two types of alerts. Classic Alerts: This is the alerts when Application Insights and Log Analytics alerts are separated. Unified Alerts: This is the latest way which I introduce in this article.


1 Answers

It is possible to define an action group with function trigger action type from the Alerts blade. As you see from the picture below, App Service Auth cannot be enabled on the function.

enter image description here

You can also raise the alert from a custom query created in Analytics. E.g. search for all trace logs for the last hour containing the word "Error":

traces |
where message contains "Error" and timestamp >= ago(1h)

enter image description here

Save the query and create a new alert rule and use that query as the alert criteria.

Access the event content in your function:

HttpRequestMessageFeature feature = new HttpRequestMessageFeature(request.HttpContext);
HttpRequestMessage req = feature.HttpRequestMessage;

var content = await req.Content.ReadAsStringAsync();

Then use WindowsAzure.Storage SDK to push the contents to blob.

var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(containerName);

var blockBlob = container.GetBlockBlobReference(fileName);
await blockBlob.UploadTextAsync(content).ConfigureAwait(false);
like image 197
JanneP Avatar answered Nov 27 '22 01:11

JanneP