How to enable logging in Power Apps

Hello everyone and welcome to my blog. Today’s blog is on Trace function in Power Apps and how you can use tracing in canvas apps to debug specific use cases.

Through my blog I share interesting tips and discuss on latest releases of Microsoft.NET technologies, Dynamics 365 and Power Platform, SharePoint and Client scripting libraries. Please subscribe to my blog to stay updated.

Let’s get it straight. Canvas apps are low code frameworks but if something does not work as expected, they are hard to debug. Unlike traditional programming, you cannot enable breakpoints and evaluate those breakpoints at run time.

The Trace function however can certainly ease the process of debugging. Let’s see this in action.

For this demo, I have a simple Power Apps screen. Illustration below.

The screen has a gallery of contacts. When an item is selected from the gallery, the selected item show up on the form beside the gallery. On click of the update button, the below formula is executed.

SubmitForm(Form1);
Trace(
    "Record submitted successfully.",
    TraceSeverity.Information,
    {
        ActiveScreen: Screen1.Name,
        RecordId: Form1.LastSubmit.Contact
    }
);
// create a related task for update operation
UpdateContext(
    {
        newTaskId: Patch(
            Tasks,
            Defaults(Tasks),
            {
                Subject: "Task for update operation",
                Regarding: Form1.LastSubmit
            }
        )
    }
);
Trace($"Task with Id: {newTaskId.Task} created successfully.");

Let’s breakdown the above formula in multiple steps.

  • Update the contact record.
  • Use the Trace function to log a message. Observe how you can specify the type of Trace, whether Information or Error. Also a custom record as the third parameter where you can pass additional information for logging.
  • Create a task
  • Log the newly created task record id using Trace statement. This time the Trace statement is simpler with just the message.

As you observed, you can use the Trace statement parameters depending on your need. Another important part to explore is where do the trace statements get logged. And the best way to quote it is from Microsoft Learn.

When used in Power Apps, the output from Trace appears in the Power Apps Monitor tool along with other app activities. If you’ve allowed your app to send telemetry data to Azure Application Insights, the Trace function can also be used to send information to your Application Insights resource

Let’s see how Trace statements can be viewed from Monitor. The first step is obviously to launch the monitor.

Once the monitor is opened, launch the app and perform the operations for which you have Trace statements. You should see your Trace operations in the monitor.

Select any of these Trace operations to view the details. You should be able to see all details of your Trace in the data property.

This can turn out to be extremely beneficial especially in case of complex apps with large formula. You can put Trace statements at each of the steps to identify the flow in the app.

I hope this helped. If you have liked the post and if this post has helped you, please subscribe to my blog.

Debajit Dutta


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading