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 Azure Application Insights connector for Logic Apps is the right tool for this purpose.

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 add additional actions as well. 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 Analytics autocluster algorithm to group attributes in the data for a web application. The flow automatically sends the results by email, just one example of how you can use Application Insights Analytics and Logic Apps together.

Step 1: Create a logic app

  1. Sign in to the Azure portal.

  2. Click Create a resource, select Web + Mobile, and then select Logic App.

    New logic app window

Step 2: Create a trigger for your logic app

  1. In the Logic App Designer window, under Start with a common trigger, select Recurrence.

    Logic App Designer window

  2. In the Interval box, type 1 and then,Frequency box, select Day.

    Logic App Designer "Recurrence" window

Step 3: Add an Application Insights action

  1. Click New step.

  2. In the Choose an action search box, type Azure Application Insights.

  3. Under Actions, click Azure Application Insights - Visualize Analytics query.

    Logic App Designer "Choose an action" window

Step 4: Connect to an Application Insights resource

To complete this step, you need an application ID and an API key for your resource. You can retrieve them from the Azure portal, as shown in the following diagram:

Application ID in the Azure portal

Application ID in the Azure portal

Provide a name for your connection, the application ID, and the API key.

Logic App Designer flow connection window

Step 5: Specify the 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. 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 are working properly in Analytics before you add it to your flow.

  1. In the Query box, add the following 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()
    
  2. In the Chart Type box, select Html Table.

    Analytics query configuration window

Step 6: Configure the logic app to send email

  1. Click New step.

  2. In the search box, type Office 365 Outlook.

  3. Click Office 365 Outlook - Send an email.

    Office 365 Outlook selection

  4. In the Send an email window, do the following:

    a. Type the email address of the recipient.

    b. Type a subject for the email.

    c. Click anywhere in the Body box and then, on the dynamic content menu that opens at the right, select Body.

    d. Click the Add new parameter drop down and select Attachments and Is HTML.

    Office 365 Outlook configuration

    Office 365 Outlook configuration

  5. On the dynamic content menu, do the following:

    a. Select Attachment Name.

    b. Select Attachment Content.

    c. In the Is HTML box, select Yes.

    Office 365 email configuration screen

Step 7: Save and test your logic app

  • Click 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.

Logic app creation screen

When your logic app runs, the recipients you specified in the email list will receive an email that looks like the following:

Logic app email message

Next steps