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?
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.
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.
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.
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)
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With