Monitor Power Apps through Azure Application Insights

How to monitor errors from Power Apps using Azure Application Insights.

Monitor Power Apps through Azure Application Insights

Overview

All credit goes to Matthew Devaney for introducing this to me. We can use Azure Application Insights to monitor our Power Apps apps errors. This is useful if users receive an unhandled error in Power Apps. We can go to Application Insights and search through the logs to find the exact error, including what control they clicked on and what the error was.

I won’t create an entire article on how to do this since Mathew’s article already goes into the details. Instead, I’ll share the basics as a quick reference.

Configure Power Apps

In the Power App App.OnError, add a Notify function to show a more detailed notification to the user. Add the Trace function to log the error details so Application Insights can pick it up.

Notify(
    Concatenate(
        FirstError.Message,
        ", Observed: ",
        FirstError.Observed,
        ", Source: ",
        FirstError.Source
    ),
    NotificationType.Error
);
Trace(
    "Unhandled Error",
    TraceSeverity.Error,
    {
        Kind: FirstError.Kind,
        Message: FirstError.Message,
        Observed: FirstError.Observed,
        Screen: App.ActiveScreen.Name,
        Source: FirstError.Source,
        User: User().Email
    }
)
This will only capture unhandled exceptions. If you use the IfError function, they will not be logged since they are handled exceptions.

Configure Application Insights

In Azure Portal, you’ll go to Application Insights and create a new entry for each app to which you want to add this. Copy the Instrumentation Key on the Overview page and paste it into the Instrumentation Key Property of the App object in your Power App.

View Application Insight logs

In Application Insights, you can click Log and enter the below query to return all of the Unhandled Errors.

traces
| where message =="Unhandled Error"
We could also use the Trace function to track information in the app by changing the name of the message and the TraceSeverity to Information.

The log shows all kinds of details, including the name of the control the user clicked on, the user, screen, error message, and even information on the version of Power Apps they're using.

A small sample of the error details that are logged.