Telemetry in Power Platform using Application Insights

Telemetry

Telemetry is the process of collecting usage, performance, and process-level information from the application into some kind of data store, which then can be used by application developers or system administrators to improve, diagnose or support the application.


Application Insights

Application Insights as defined by Microsoft is “a feature of Azure Monitor, is an extensible Application Performance Management (APM) service for developers and DevOps professionals. Use it to monitor your live applications. It will automatically detect performance anomalies and includes powerful analytics tools to help you diagnose issues and to understand what users actually do with your app. It's designed to help you continuously improve performance and usability”, so in other words, Application Insights is Microsoft’s technology to provide telemetry and instrumentation services for Applications, there are various SDKs and packages available that allows developers to connect to Application Insights Service from their application and pass the instrumentation data, more on Application Insights can be found here.


What does Application Insights have to do with Power Platform?

Power Platform allows Pro and Citizen developers to build both simple and sophisticated applications for all kinds of devices and browser types, As a developer where fulfilling the business requirements and designing it accordingly is extremely important but on top of that having enough insights into how this application is being used is also very handy in the evolution and improvement of the apps. Realizing this Microsoft has provided native integration with Application Insights and made it very easy for developers to set it up

In this post, we will cover how to set application insights and connect them to Canvas Apps, Model-Driven Apps, and Portals, and what kind of information can we extract from this.


Setting up Application Insights



  • Find Application Insights in the search bar


  • Click Create

  • Provide the parameters and click Review + Create

  • Click Create if everything looks OK on the review page

  • This will start the Application Insights deployment process

  • Once done, click Go to Resource to navigate to the Application Insights Overview

  • Copy the Instrumentation Key for later steps


Connecting Canvas Apps to Application Insights

  • Edit your Canvas App and open it in Creator Portal

  • Once the app is open for editing, Click on the App icon in the left-hand navigation (Tree View)

  • Paste the Instrumentation Key copied from Application Insights Overview Page in the Instrumentation Key field

  • Save & Publish the App




Connecting PowerApps Portal to Application Insights

  • Open the Portal Management Model Driven App


  • Navigate to Enable Traffic Analytics link in the side navigation


  • Select the Portal in Website field, and copy the below script in the snippet section, make sure you replace the Instrumentation Key with your key and click Save




<script type="text/javascript">
     var appInsights=window.appInsights||function(a){
         function b(a){c[a]=function(){var b=arguments;c.queue.push(function(){c[a].apply(c,b)})}}var c={config:a},d=document,e=window;setTimeout(function(){var b=d.createElement("script");b.src=a.url||"https://az416426.vo.msecnd.net/scripts/a/ai.0.js",d.getElementsByTagName("script")[0].parentNode.appendChild(b)});try{c.cookie=d.cookie}catch(a){}c.queue=[];for(var f=["Event","Exception","Metric","PageView","Trace","Dependency"];f.length;)b("track"+f.pop());if(b("setAuthenticatedUserContext"),b("clearAuthenticatedUserContext"),b("startTrackEvent"),b("stopTrackEvent"),b("startTrackPage"),b("stopTrackPage"),b("flush"),!a.disableExceptionTracking){f="onerror",b("_"+f);var g=e[f];e[f]=function(a,b,d,e,h){var i=g&&g(a,b,d,e,h);return!0!==i&&c["_"+f](a,b,d,e,h),i}}return c
     }({
         instrumentationKey: "YOUR_INSTRUMENTATION_KEY_GOES_HERE"
     });

     window.appInsights=appInsights,appInsights.queue&&0===appInsights.queue.length&&appInsights.trackPageView();
</script>




Connecting Model-Driven Apps to Application Insights


This feature is currently in public preview and the general availability has not been disclosed yet.

  • Log on to Power Platform Admin Center at https://admin.powerplatform.microsoft.com using Global Admin or Power Platform Admin account

  • Click on Data Export (preview) on side navigation and navigate to App Insights Tab

  • Click on New Data Export button in the toolbar

  • Select CDS diagnostics and performance under Export to Application Insights

  • Select the environment and click Next



What can we use this Telemetry Data for?


Well this warrants a blog post in itself, but I'll give you a quick summary of the various kind of information Application Insight is collecting from Power Apps


This includes


  • User Details and their break down by Location, OS, and Browsers, this allows you to pick up certain behaviors based on these breakdowns, it also assess the application performance in terms of load time


  • Session Details, a user can have multiple sessions on an app, so each session data is also recorded



  • Event Details, events are certain trigger points that happen inside the app, it can be system-generated like when a screen is loaded or a custom event that can be captured by the developer using Tracing


  • User Flows captures a general flow of applications based on a certain starting point




Conclusion

So folks, this was a quick summary of what Application Insights is, how you can connect to it in Power Apps and what kind of useful information you can get out of it