Categories: Microsoft Office 365

Azure Application Insights and Error Handling in Power Apps

This post is all about error handling in Power Apps with Azure Application Insight. Logging all events in your app (wanted and unwanted) within an easy to use log.

Enable the Application Insight feature

To enable the Azure Application Insights integration we will first need to enable to Pass errors to Azure Application Insights.

Pass errors to Azure Application Insights

If however you want to also catch any erroring code you will also need to enable the Formula-level error management feature.

Pass errors to Azure Application Insights feature switched on

Both of these features are experimental so please use these with care.

Create Application Insight Resources

If you haven’t already configured Azure Application Insights then you might want to go to your Azure Portal and create the required resources. It should look something like this:

Application Insights

Instrumentation Key

Once the resources are created you will need to take a copy of the Instrumentation Key. The Instrumentation Key is the link between your Power Apps and your Application Insights configuration.

Copy Instrumentation Key

Now within your app you can use this key. Simply go to your app and set the Instrumentation key property.

Set Instrumentation key

Once you have published your app and run the published app (not from Power Apps Studio!), you will find that the Usage reports will show some graphs with details on users, events and so much more.

Application insights users

In this post however I want to focus on the reporting of the error handling.

Using the trace function

In my app I can now write messages to the trace log in my Azure Application Insights using the trace function. The trace function has three parts to it. The Message, the message level and an object that can contain any information. Just to proof the point that the object can be anything I included a typo in one of the properties.

Trace function in action

And as users are using my app, the information messages now appear within my log

Just some information message appearing

On the above log you can find information such as who ran the app and when. Just imagine creating a trace every time someone starts the app and you include the version number of the app in the details. You never need to ask a user which version they were running again!

Error Handling

So far I only used an information message. Although very useful in many ways, you might also want to report errors in the code. Maybe even automatically log a ticket in your helpdesk system when things go wrong, or email a developer to fix the issues.

Now, I’m going to make use of the IfError function to identify issues within my horrible code.

Error Handling with Azure Application Insights in Power Apps

Both my Patch and my Set lines of code will fail and the IfError function will now run the Trace to report the issues. Notice that the Severity Level of the error has been changed to Error

Now when I run the app and click on the button I will see the error message coming through.

Collect Errors
Share
Pieter Veenstra

Business Applications Microsoft MVP working as the Head of Power Platform at Vantage 365. You can contact me using contact@sharepains.com

Recent Posts

Introducing 8 AI Functions for Dataverse in Power Apps

Recently Microsoft added AI Functions to Dataverse that can be used in Power Apps. In…

2 days ago

Copy and paste Scope steps in the new Power Automate Designer

One of the outstanding issues with the new Power Automate Designer is Copy and Paste…

1 week ago

Receive the available storage within your SharePoint Online tenant

Within the SharePoint admin centre there is that little detailed overview, telling you the available…

1 month ago

Options for Documenting Your Power Apps: Comments, Code, and Controls

Within Power Apps there are various ways to document your app. In this post I'm…

1 month ago

2 ways to duplicate SharePoint Lists to support your Power Apps

Recently I've been asked quite a few times to duplicate SharePoint lists as part of…

1 month ago

Update a Hyperlink Column in SharePoint with Power Automate

Today, I was asked about how to create a lookup to a document or item…

1 month ago