Trace function

Applies to: Canvas apps Model-driven apps Power Platform CLI

Often there is a lot of logic working behind the scenes in an app. Sometimes the impact is obvious, for example a control's value or color changes, confirming the logic operated correctly. However, sometimes it isn't obvious and it can be difficult to visualize and understand what is happening inside the app. Use the Trace function to record diagnostic information from behind the scenes, creating a timeline of what actually happened, to better understand how your app is operating and to help debug issues.

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. Trace can only be used in behavior formulas.

When used with Test Studio, Trace is an optional expression that can be used to provide additional information in your test results from the OnTestCaseComplete event. Trace event messages are combined with passed and failed assertion messages in the Traces table of the TestCaseResult record. The Traces table has two properties, Message and Timestamp. Trace information used in tests will also be recorded in Application Insights. Test trace information won't be available in the Monitor tool as the Monitor is connected to the app when it's played from the Power Apps Studio.

Syntax

Trace( Message [, TraceSeverity [, CustomRecord [, TraceOptions ] ] ] )

  • Message – Required. The information to be traced. Numbers, Dates, Booleans and any other data type that can be coerced to Text.
  • TraceSeverity – Optional. The severity level of the Trace recorded in Monitor and Application Insights. Options are TraceSeverity.Information (default), TraceSeverity.Warning, TraceSeverity.Error, or TraceSeverity.Critical.
  • CustomRecord – Optional. A record containing custom data that will be recorded in Monitor or Application Insights.
  • TraceOptions – Optional. Options are TraceOptions.None (default) and TraceOptions.IgnoreUnsupportedTypes which will ignore data types in CustomRecord that can't be serialized.

Example

  1. Create a button control in Power Apps Studio.
  2. Set the OnSelect formula to the formula:
Set( x, x+1 );
Trace( x );
  1. Open the Power Apps Monitor in another browser window by selecting the "Advanced tools" icon in the left hand pane and select "Open monitor": entry point for Power Apps monitor
  2. Return to the original Studio browser window and select your button four times. Use Alt-click on your mouse if in design mode.
  3. View the Power Apps Monitor.
  4. The Monitor's grid will contain an event for each button click and for each Trace call, which will show the value of the variable after each increment. Drill into a Trace event to see where the Trace was initiated, and the expression used for the message, in the right hand panel: monitor trace showing button being pressed four times and corresponding increments of a variable

See Also

Power Apps Monitor Overview
Test Studio Overview
Working with Test Studio