Skip to content

Commit 22aa30e

Browse files
authored
add udf-trace snippet (#58)
This snippet demonstrates how to implement telemetry logging in Power Apps using User Defined Functions (UDFs) and Azure Application Insights. It showcases the definition and application of UDFs to efficiently manage and send telemetry data.
2 parents 790d160 + 31f667f commit 22aa30e

File tree

10 files changed

+564
-0
lines changed

10 files changed

+564
-0
lines changed

power-apps/udf-trace/README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Send telemetry logs with User Defined Functions to Azure Application Insights
2+
3+
This snippet demonstrates how to implement telemetry logging in Power Apps using User Defined Functions (UDFs) and Azure Application Insights. It showcases the definition and application of UDFs to efficiently manage and send telemetry data.
4+
5+
![preview](./assets/udf-trace.png)
6+
7+
## Problem statement
8+
9+
Telemetry collection is crucial for developing and enhancing apps. In Power Apps, developers use the `Trace()` function to send telemetry logs to Azure Application Insights.
10+
11+
However, using this function independently often results in inconsistencies in trace parameters, message formats, and severity levels. These variations can lead to errors and lack a standardized approach, affecting the reliability and usefulness of the data collected. Additionally, without properly preparing the data for logging, it could also cause redundant nests, making the logs harder to parse and analyze effectively.
12+
13+
## Solution
14+
15+
By implementing a standardized `User Defined Function (UDF)` for telemetry, it's possible to ensure consistent data collection, minimize errors, and improve the analysis and utility of application insights.
16+
17+
## Authors
18+
19+
Author|Socials
20+
--------|---------
21+
Katerina Chernevskaya | [GitHub](https://github.com/Katerina-Chernevskaya/) - [LinkedIn](https://www.linkedin.com/in/katerinachernevskaya/)
22+
23+
## Prerequisites
24+
25+
1. Existing Azure Application Insights resource. Learn more how to create Azure Application Insights resource [here](https://learn.microsoft.com/en-us/azure/azure-monitor/app/create-workspace-resource?tabs=portal).
26+
27+
2. Connect your Power Apps Canvas app to Application Insights. You can follow the [official guide](https://learn.microsoft.com/en-us/power-apps/maker/canvas-apps/application-insights#connect-your-app-to-application-insights) or use the steps below:
28+
- Go to your Application Insights resource in Azure. On the **Overview** page, locate and copy the **Connection String**:
29+
![Connection String - Copy](./assets/key.png)
30+
- In Power Apps Studio, select the **App** level, then navigate to the **Connection string** property on the right-hand pane and paste the copied value:
31+
![Connection String - Paste](./assets/key-paste.png)
32+
33+
3. Make sure that experimental features are enabled:
34+
- User-defined functions
35+
- User-defined types
36+
![experimental-features](./assets/experimental-features.png)
37+
38+
4. Power Apps Canvas app with the following controls (name the controls the same as in the list below). You can use the [sample screen snippet](./source/screen.pa.yaml) to quickly add a preconfigured screen with all necessary controls.
39+
- DatePicker
40+
- Slider
41+
- Gallery
42+
- RadioGroup
43+
- Dropdown
44+
- Toggle
45+
- Rating
46+
- Combobox
47+
- Checkbox
48+
- Button
49+
50+
## Minimal path to awesome
51+
52+
1. Open your Power App in edit mode
53+
2. Copy the contents of the **[udf.fx](./source/udf.fx)**
54+
3. Add the copied code into `Formula` property on the `App` level
55+
4. *(Optional: if you didn't create the screen with the [sample screen snippet](./source/screen.pa.yaml))* Copy the contents of the **[onselect.fx](./source/onselect.fx)** and insert the copied code into the `OnSelect` property of the Button
56+
5. Make sure the screen with controls is easily accessible - either move it to a higher position in the screen list or add a navigation control to reach it. Save the app and publish it
57+
6. Play the app, test the button to send telemetry to Azure Application Insights
58+
7. Navigate to the Azure Application Insights resource. Open the `Logs` under `Monitoring`. Select `trace` table. You will see the collected telemetry under the `customDimensions`
59+
![Azure Application Insights](./assets/aap.png)
60+
61+
## Disclaimer
62+
63+
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
64+
65+
<img src="https://m365-visitor-stats.azurewebsites.net/powerplatform-snippets/power-apps/udf-trace" aria-hidden="true" />

power-apps/udf-trace/assets/aap.png

108 KB
Loading
Loading
181 KB
Loading

power-apps/udf-trace/assets/key.png

65.4 KB
Loading
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[
2+
{
3+
"$schema": "https://developer.microsoft.com/en-us/json-schemas/pnp/samples/v1.0/metadata-schema.json",
4+
"name": "pnp-powerplatform-snippets-udf-trace",
5+
"version": "1.0.0.0",
6+
"source": "pnp",
7+
"creationDateTime": "2025-04-02T00:00:00.000Z",
8+
"updateDateTime": "2025-04-02T00:00:00.000Z",
9+
"title": "Send telemetry logs with User Defined Functions to Azure Application Insights",
10+
"shortDescription": "This snippet demonstrates how to implement telemetry logging in Power Apps using User Defined Functions (UDFs) and Azure Application Insights. It showcases the definition and application of UDFs to efficiently manage and send telemetry data.",
11+
"longDescription": [
12+
"This sample demonstrates a structured approach to telemetry logging in Power Apps using the Trace() function with Azure Application Insights. It addresses common issues that arise when Trace() is used inconsistently - such as mismatched parameters, varying message formats, and unstandardized severity levels. These inconsistencies can lead to unreliable telemetry data and complicate analysis. The sample also highlights the importance of preparing data properly before logging to avoid redundant nesting, which can make logs more difficult to parse and interpret."
13+
],
14+
"url": "https://github.com/pnp/powerplatform-snippets/tree/main/power-apps/udf-trace/",
15+
"products": [
16+
"Power Platform",
17+
"Power Apps",
18+
"powerplatform-snippets",
19+
"power-apps-snippets",
20+
"formula-snippets"
21+
],
22+
"tags": [ ],
23+
"categories": [ ],
24+
"metadata": [
25+
{
26+
"key": "Product",
27+
"value": "Power Apps"
28+
},
29+
{
30+
"key": "Type",
31+
"value": "Formula"
32+
}
33+
],
34+
"thumbnails": [
35+
{
36+
"type": "image",
37+
"order": 100,
38+
"url": "https://raw.githubusercontent.com/Katerina-Chernevskaya/powerplatform-snippets/dc573cf7bc535f6072dcaa5abf2d91ebb270f53d/power-apps/udf-trace/assets/udf-trace.png",
39+
"alt": "Preview PNG"
40+
}
41+
],
42+
"authors": [
43+
{
44+
"gitHubAccount": "Katerina-Chernevskaya",
45+
"name": "Katerina Chernevskaya",
46+
"pictureUrl": "https://github.com/Katerina-Chernevskaya.png"
47+
}
48+
]
49+
}
50+
]
528 KB
Loading
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
udfTrace(
2+
DatePicker.SelectedDate,
3+
Slider.Value,
4+
ShowColumns(
5+
Filter(
6+
Gallery.AllItems,
7+
status = "Yes" // Replace status with your gallery property name
8+
),
9+
title // Replace title with your gallery property name
10+
),
11+
RadioGroup.SelectedItems,
12+
Dropdown.SelectedItems,
13+
Toggle.Checked,
14+
Rating.Value,
15+
Combobox.SelectedItems,
16+
Checkbox.Checked
17+
)

0 commit comments

Comments
 (0)