Exercise - Collect and analyze telemetry data

Completed

In this exercise scenario, you have been asked to collect telemetry data from the Cost Estimator application. You have decided to use Application Insights to collect and analyze the telemetry data.

Tasks

The tasks that you'll complete in this exercise are:

  • Add trace that will track viewed jobs.

  • Add trace that will track jobs from validation errors.

Objectives

The objectives of this exercise are to show you how to:

  • Create an Application Insights app in Azure.

  • Connect a canvas app to Application Insights.

  • Add traces to your application.

  • Query trace logs.

Prerequisites

Make sure that you meet the following prerequisites before beginning the exercise:

  • An environment with Microsoft Dataverse installed

  • A Microsoft Azure subscription: Azure - Sign up

Exercise 1: Import a solution

In this exercise, you'll import a solution into your environment. This solution contains a working canvas application. You'll modify it later to add tracing to certain user actions and then analyze the results.

Task: Import a solution

In this task, you'll import a solution into your environment.

  1. You'll need to download the zip file to complete this exercise. Select download once the link opens.

  2. Go to Power Apps maker portal and select the environment that you want to use for this lab.

  3. Select Solutions > Import.

    Screenshot of the Import button in the Solutions area.

  4. Select Browse.

  5. Select the ContosoCostEstimator_1_0_0_1.zip solution, and then select Open.

  6. Select Next.

  7. Select Import and then wait for the solution importing to complete.

Exercise 2: Set up the app

In this exercise, you'll set up the app for Application Insights. If you have an active Azure subscription that is associated with your lab user, follow the steps in this section. If you don't have an active Azure subscription, you'll be prompted to add it while following these steps. The free Azure subscription that is offered will be enough for you to complete this lab.

Task: Create an Application Insights app

In this task, you'll create an Application Insights app in Microsoft Azure, which requires an active Azure subscription. If you don't have an Azure subscription, you can sign up.

  1. Go to the Microsoft Azure portal and select Create a resource.

    Screenshot of the Create a resource button.

  2. Search for and select Application Insights.

  3. Select Create.

  4. Select your subscription and then select Create new under the Resource Group dropdown list.

  5. Enter fl_insights for Name and then select OK. Replace fl with your initials.

    Screenshot of the create resource group window.

  6. Enter Insights_Lab for Name, select your Region, and then select Review + create.

  7. Select Create and then wait for the resource to be created.

  8. Select Go to resource.

  9. Copy the Instrumentation Key.

    Screenshot of the Instrumentation Key.

  10. Go to the Power Apps maker portal and select the environment that you're using for this lab.

  11. Select Solutions and then select to open the Contoso Cost estimator solution that you imported.

  12. Select to open the Cost Estimator application. The application should open in app studio.

  13. Select App, go to the Properties pane, and then paste the instrumentation key that you copied from the Instrumentation Key field.

    Screenshot of the Instrumentation key pasted in the properties.

  14. Select the Save icon.

  15. Select the Publish icon.

  16. Select Publish this version and then wait for the publishing to complete.

  17. Select the back button.

  18. Select Play.

  19. Make sure that the app loads the data.

    Screenshot of the Cost Estimator application.

  20. Close the preview.

  21. Don't navigate away from this page.

Exercise 3: Edit and add trace

In this exercise, you'll add trace to the application by modifying formulas that are already part of the working app from Power Apps.

Task: Add trace

In this task, you'll add trace to the application.

  1. Expand OpenJobsPage.

  2. Expand JobsListGallery and then select icon2.

    Screenshot of the icon control.

  3. Append the OnSelect value of icon2 with the following formula. This trace will track which jobs are being viewed.

    ;Trace("Job Viewed",TraceSeverity.Information,{JobId:ThisItem.JobId, JobName:ThisItem.JobName})

    Screenshot of the formula being edited.

  4. Select NewJob page from the Tree view.

  5. Select the Save job button.

    Screenshot of the Save job button.

  6. Go to the formula bar, select OnSelect, and then expand the formula bar.

    Screenshot of the expand formula bar button.

  7. Select Format text.

    Screenshot of the Format text button.

  8. Scroll down and locate UpdateContext. Two occurrences should be shown.

    Screenshot of the two UpdateContext occurrences.

  9. Add the following formula after the first UpdateContext occurrence.

     ;
     Trace(
             "Validation Failed",
             TraceSeverity.Warning,
             {
                 JobName: IsBlank(TextInputClientName.Text),
                 ContactName: IsBlank(TextInput1_15.Text),
                 Phone: IsBlank(TextInputPhone.Text),
                 Email: IsBlank(TextInputEmail.Text),
                 AppointmentDate: IsBlank(TextInputDate.Text),
                 AppointmentTime: IsBlank(TextInputTime.Text)
             }
         )
    

    Screenshot of the formula edit area.

  10. Go to the second UpdateContext occurrence and add the same formula.

    Screenshot of the second formula edit area.

  11. Select the Save icon.

  12. Select the Publish icon.

  13. Select Publish this version and then wait for the publishing to complete.

  14. Close the app studio browser window or tab.

Exercise 4: Run the published app

In this exercise, you'll run the published application, which will trigger the tracing that you added. Additionally, it will give you data to analyze in the steps that follow.

Task: Run the application

In this task, you'll run the application that you published.

  1. Go to the Power Apps maker portal and make sure that you are in the correct environment.

  2. Select Apps and then select to launch the Cost Estimator application.

  3. Select to open a job.

    Screenshot of the row from the gallery.

  4. Select the back button.

  5. Open another job and then select the back button again.

  6. Open a few more jobs.

  7. Select the plus (+) icon to add a job.

  8. Select Save job without providing data, which will give you data to analyze where the user didn't follow the expected data entry path.

    Screenshot of the Cost Estimator form.

  9. Provide a Client name and then select Save job.

  10. Provide an Email and then select Save job.

  11. Provide an Address and then select Save job.

  12. Provide City and State information and then select Save job.

  13. Provide Zip code and Phone information and then select Save job.

    Screenshot of the completed Cost Estimator form.

    The job should be saved.

  14. Create another job, but this time, provide a contact name and then leave some of the required fields empty.

Exercise 5: View Application Insights

In this exercise, you'll view Application Insights.

Task: View Application Insights

In this task, you view Application Insights.

  1. Go to the Microsoft Azure portal and make sure that you are in the correct environment.

  2. Select to open the Insights_Lab resource that you created.

    Screenshot of the Insights_Lab resource.

  3. Scroll down to the Usage section and select Users.

    Screenshot of the Users option in the Usage section.

  4. At least one user should display. If at least one user doesn't show, edit the app again, make sure that you provided the correct Instrumentation key, and then publish it again.

    Screenshot showing one user in the user count.

  5. From the chart, scroll down and select View more insights in the lower left of the chart.

    Screenshot of the View More Insights button.

  6. At least five events should show. If at least five events don't show, then return to Exercise 4 and complete it again. Wait for five minutes before continuing.

  7. Scroll down and select View user timeline.

    Screenshot of the View user timeline button.

  8. Information about the use location and events should display. Select to expand the session.

    Screenshot of the expand session button.

  9. View the listed events.

    Screenshot of the session events.

  10. Go to the Monitoring section and select Logs.

    Screenshot of the Logs button.

  11. Close the Queries pop-up window.

  12. Don't navigate away from this page.

Exercise 6: Query the logs

In this exercise, you'll query the logs.

Task: Query the logs

In this task, you'll query the logs.

  1. Type pageViews and then select Run.

    Screenshot of the Run query button.

  2. Go to the Results tab.

  3. Traces should display. Scroll up/down and left/right to view what was traced.

  4. Expand one of the results and then select to expand customDimensions.

    Screenshot of the expand button next to customDimensions.

  5. Change the query to traces and then select Run again.

    Screenshot of the Run query button to run it again.

  6. Expand one of the results and then select to expand customDimensions.

  7. Filter for validation logs. Replace the query with the following query logic and then select Run.

     traces
     | where message =="Validation Failed"
    

    Screenshot of the query traces with the Run button highlighted.

  8. Expand one of the results and then select to expand customDimensions.

    Screenshot of the query results.

  9. Query for jobs without a contact name. Paste the following query and then select Run.

    Screenshot of the trace query showing the Run button.

    You should get traces with no contact name.