6
votes

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?

1
yes it is, when you configure an alert, you can specify a webhook endpoint. azure.microsoft.com/en-us/blog/webhooks-for-azure-alertsThomas

1 Answers

2
votes

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);