6

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?

Kuczi
  • 357
  • 4
  • 18
  • 1
    yes it is, when you configure an alert, you can specify a `webhook` endpoint. https://azure.microsoft.com/en-us/blog/webhooks-for-azure-alerts/ – Thomas Jun 08 '18 at 23:08

1 Answers1

2

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);
JanneP
  • 577
  • 4
  • 12
  • So having this Action Group enables me to run the specified function whenever this action group is "called". I'm marking this as the chosen answer. Do you also happen to know, how i can raise an Alert whenever the function fails? I only see the alerts that can be triggert by some metrics in a period of time. – Kuczi Jun 11 '18 at 12:18
  • Is it even possible to use Application Insights for monitoring Logic Apps? Or does it only work with App Services? – Kuczi Jun 11 '18 at 12:22
  • I've added more details to my answer, check the updates on custom error logging with Analytics. I believe you could monitor Logic Apps with OMS suite or by calling functions, I'm not exactly familiar with Logic Apps so these are just ideas... – JanneP Jun 11 '18 at 19:17