Automate Application Insights processes by using Logic Apps
Do you find yourself repeatedly running the same queries on your telemetry data to check whether your service is functioning properly? Are you looking to automate these queries for finding trends and anomalies and then build your own workflows around them? The Application Insights connector for Azure Logic Apps is the right tool for this purpose.
The Application Insights connector has been replaced by the Azure Monitor connector. It's integrated with Azure Active Directory instead of requiring an API key. You can also use it to retrieve data from a Log Analytics workspace.
With this integration, you can automate numerous processes without writing a single line of code. You can create a logic app with the Application Insights connector to quickly automate any Application Insights process.
You can also add other actions. The Logic Apps feature of Azure App Service makes hundreds of actions available. For example, by using a logic app, you can automatically send an email notification or create a bug in Azure DevOps. You can also use one of the many available templates to help speed up the process of creating your logic app.
Create a logic app for Application Insights
In this tutorial, you learn how to create a logic app that uses the Log Analytics autocluster algorithm to group attributes in the data for a web application. The flow automatically sends the results by email. This example shows how you can use Application Insights analytics and Logic Apps together.
Create a logic app
Sign in to the Azure portal.
Select Create a resource > Web > Logic App.
Create a trigger for your logic app
In the Logic Apps Designer window, under Start with a common trigger, select Recurrence.
In the Interval box, enter 1. In the Frequency box, select Day.
Add an Application Insights action
Select New step.
In the Choose an action search box, enter Application Insights.
Under Actions, select Visualize Analytics query - Azure Application Insights.
Connect to an Application Insights resource
For this step, you need an application ID and an API key for your resource.
Select API Access > Create API key.
Provide a name for your connection, the application ID, and the API key.
Specify the Log Analytics query and chart type
In the following example, the query selects the failed requests within the last day and correlates them with exceptions that occurred as part of the operation. Log Analytics correlates the failed requests based on the
operation_Id identifier. The query then segments the results by using the autocluster algorithm.
When you create your own queries, verify that they're working properly in Log Analytics before you add them to your flow.
In the Query box, add the following Log Analytics query:
requests | where timestamp > ago(1d) | where success == "False" | project name, operation_Id | join ( exceptions | project problemId, outerMessage, operation_Id ) on operation_Id | evaluate autocluster()
In the Chart Type box, select Html Table.
Configure the logic app to send email
Select New step.
In the search box, enter Office 365 Outlook.
Select Send an email - Office 365 Outlook.
In the Send an email window:
Enter the email address of the recipient.
Enter a subject for the email.
Select anywhere in the Body box. On the Dynamic content menu that opens at the right, select Body.
Select the Add new parameter dropdown list and select Attachments and Is HTML.
On the Dynamic content menu:
Select Attachment Name.
Select Attachment Content.
In the Is HTML box, select Yes.
Save and test your logic app
Select Save to save your changes.
You can wait for the trigger to run the logic app, or you can run the logic app immediately by selecting Run.
When your logic app runs, the recipients you specified in the email list will receive an email that looks like this example:
The log app generates an email with a JPG file that depicts the query result set. If your query doesn't return results, the logic app won't create a JPG file.