Log Canvas Power App telemetry data in Azure Application Insights | Power Apps

Here’s how you can register your Canvas Power App in your Azure’s Application Insights and log telemetry data into Azure.

Some basic info about what all you can see in Application Insights is –

  1. Count of Users who used the app
  2. Events logged, Sessions logged
  3. Device info
  4. Region info

It’s quite simple to set it up! Let’s take a look –

Registering in Application Insights in Azure

First, make sure you do have an Azure Subscription. Let’s look at how you can register an Application Insight record.

  1. Look for Application Insights in Azure in the search bar

  2. Then, among other records, you can register a new one which will identify with your Canvas Power App

  3. Review all that you entered and move ahead

  4. It’ll be deployed pretty quickly within a few minutes unlike some heavy Azure resources

  5. Upon completion, you can navigate to the resource and see the details

    Zoomed In


Add Instrumentation Key to Canvas Power App

Next step is to add the Instrumentation Key to the Canvas Power App

  1. Look for the App itself in the Navigation tree

  2. Once you select that, you can then look at it’s Properties on the right hand side. In Instrumentation Key, paste the Instrumentation Key you copied when you created the App in the Azure.

  3. And to go with that, let’s say my Canvas Power App has some basic structure like below

Using Application Insights

As the users use the Canvas App, the following information is logged –

  1. Navigate to the Usage section in the Application Insights you registered and if you scroll down on the main pane, you can see w

  2. And then scroll down to reveal more Insight data


  3. Or, if you see Events, you can see info like this –

    I’m not completely sure why my users showed high when I tried with only 2 users. But perhaps, once I dive more deeper into using Application Insights and how each of the metrics are read, I’ll come back to update this post. 😊

And likewise, if you know how to read the Application Insights, you can customize this to give you what you need to see.

Here is some Microsoft Documentation on Application Insights to help you out –

  1. https://docs.microsoft.com/en-us/azure/azure-monitor/app/usage-segmentation

Hope this was useful. Here are more Azure/Canvas Power App related posts you might want to check –

  1. Call Azure Function from Dynamics 365 CRM using Webhooks
  2. Use Azure App Passwords for MFA enabled D365 authentication from Console App
  3. Call HTTP Request from a Canvas Power App using Flow and get back Response | Power Automate
  4. Launch URL on a Data Table Text column selection in a Canvas PowerApp | SharePoint Lists
  5. Call HTTP Request from a Canvas Power App using Flow and get back Response | Power Automate
  6. Send a Power App Push Notification using Flow to open a record in Canvas App | Power Automate
  7. Aggregate functions in a Canvas Power App | Using on SharePoint Lists
  8. Count of total CDS records returned in a Canvas Power App connection [Quick Tip]
  9. Dependent OptionSets in a Canvas Power App for 1:N related CDS entities | Power Platform
  10. Implement character length validation in a Canvas Power App | Power Platform

Thank you!

Call Azure Function from Dynamics 365 CRM using Webhooks

This is a vast topic to cover in a blog. But I wanted to write from a bird-eye’s view of how this will pan out in an implementation where you perform a certain operation in Dynamics 365 CRM and an Azure Function is called to perform further operations.

This post is written keeping in mind fair knowledge of Azure Functions, Storage accounts and subscriptions in mind.

I’ll try to keep the article short, so stay with me! 🙂

Create a Function App in Azure

  1. Let’s say you have created a Function App in Azure already and want to connect to Dynamics 365 CRM. Click on the big + New Function button in the screenshot below
    resourceOverview_LI
  2. Now, since I want to keep Visual Studio as my driver for coding and deployment, I’ll create a new Project in Visual Studio of type Azure Functions and click Next
    newProj
  3. On the next page, I’ll give a relevant name and hit Create.
    createProjectButton
  4. Since we will be using Webhooks to connect to the Azure Function, the trigger chosen here is Http Trigger.Make sure you select Framework because Microsoft.Xrm.Sdk assemblies don’t work on .NET Code, but on .NETFramework only.And then you should take care of what your Storage Account and Authorization should be – Finally click Create once done.
    frameWorkSelected
  5. The Project will open with 1 .cs file, so make sure you name your plugin initially –
    accountPluginGetsInApp
  6. It’ll take a while to create the Project. Once created, go to the Portal on Azure and click on the Get Publish Profile
    getPublishProf_LI
    It will be downloaded on the computer. Keep it so that you can import it on the Project in Visual Studio to use for Direct Publish.
    downloadedProfile
  7. Now, right click and chose Publish to make your first push as is so that the Account Function gets pushed to Azure App.
    firstPublish
  8. Then, click on Import and import the Publish Profile settings downloaded in step #5 above –
    selectImport
  9. Once imported, you’ll be taken here – simply Publish once.
    quickPublish
  10. Once Publish is successful, check in the Azure App in Portal, the Function should appear.
    accountPluginGetsInApp

 

Modifying code to read Webhook Call from Dynamics 365

  1. To keep it simple, I’m simply reading the context and then, you can flourish your App further to make it work as required.
    captureContextSo, I’m only reading the request into a String and logging it so that we can see it in the logs in the Azure Function app.
  2. You can use RemoteExecutionContext class to actually get all the contextual information into the Function app and then use it further. See below –
    remotecontext
  3. Once ready with your code, Publish it.

Now, let’s Register the Webhook and call the app.

If you’re also looking for remote debugging, this is a great article-Remote Debugging Azure Functions V2 “The breakpoint will not currently be hit. No symbols have been loaded for this document”

Register a Webhook in Plugin Registration Tool

Coming to Dynamics 365 CRM side of things, you can register a Webhook that will trigger on Account Name update to fire off the AccountPlugin Function App created above –

  1. In Plugin Registration Tool, register a new Webhook
    registerWebHook
  2. Enter Webhook Details. Select Authentication type as WebhookKey
    enterWebhookDetails
  3. Now, to get the key, go to the Function App in portal, and look </> Get function URL link.
    getKeyandURL
  4. Copy the same and paste in Notepad, separate the code part from the main URL
    selectCopy
    separateCodePart
  5. Paste the URL part in Endpoint URL and key in the Value field. Click Save.
    registerWebHookWIthDetails
  6. Now, add a Step to the Webhook. For this example, I’ve chosen update of Account‘s Account Name field
    addStepregisterStepInWebhook
    And Register it.

Execution

  1. The purpose was to simply ready Dynamics 365 Account record upon modification of the Account Name
    recordChange
    And save the record.
  2. In a minute or so, the Log will be generated (only the logs take a little longer to generate)
    triggered
    And thus, we are able to send data / or rather, call Azure Function and process Dynamics 365 CRM data using Webhooks.

Some other Azure related post you might like to look at – Use Azure App Passwords for MFA enabled D365 authentication from Console App

Hope this was helpful! Tried my best to keep it basic and short as possible. I’m sure you all will explore way beyond and develop awesome implementations!