Skip to content

Commit 60aae21

Browse files
committed
Optimized telemetry
1 parent 9ab7022 commit 60aae21

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Releases
22

3+
## 1.2.3
4+
5+
- Optimized telemetry so that it only pushes control data
6+
37
## 1.2.2
48

59
**Fixes**

docs/documentation/docs/about/release-notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Releases
22

3+
## 1.2.3
4+
5+
- Optimized telemetry so that it only pushes control data
6+
37
## 1.2.2
48

59
**Fixes**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@pnp/spfx-controls-react",
33
"description": "Reusable React controls for SharePoint Framework solutions",
4-
"version": "1.2.2",
4+
"version": "1.2.3",
55
"engines": {
66
"node": ">=0.10.0"
77
},

src/common/appInsights/index.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,35 @@ import { AppInsights } from "applicationinsights-js";
22
import { version } from './version';
33
import {Environment,EnvironmentType} from "@microsoft/sp-core-library";
44

5+
const controlType = "react";
6+
57
AppInsights.downloadAndSetup({ instrumentationKey: "9f59b81e-d2ed-411e-a961-8bcf3f7f04d0" });
68

7-
// Remove operation name from the telemetry
8-
if (AppInsights.context && AppInsights.context.operation && AppInsights.context.operation.name) {
9-
AppInsights.context.operation.name = null;
10-
}
9+
appInsights.queue.push(() => {
10+
// Remove operation name from the telemetry
11+
if (AppInsights.context && AppInsights.context.operation && AppInsights.context.operation.name) {
12+
AppInsights.context.operation.name = null;
13+
}
14+
15+
// Filter out telemetry data
16+
appInsights.context.addTelemetryInitializer((envelope: Microsoft.ApplicationInsights.IEnvelope) => {
17+
const telemetryItem = envelope.data.baseData;
18+
// Only send telemetry data if it contains data of this library
19+
if (!telemetryItem.properties || !telemetryItem.properties.controlType) {
20+
return false;
21+
}
22+
23+
// Only send telemetry if it is coming from the right control type
24+
if (telemetryItem.properties && telemetryItem.properties.controlType && telemetryItem.properties.controlType !== controlType) {
25+
return false;
26+
}
27+
});
28+
});
1129

1230
export function track(componentName: string, properties: any = {}): void {
1331
AppInsights.trackEvent(componentName, {
1432
version,
33+
controlType,
1534
debug: DEBUG ? "true" : "false",
1635
environment: EnvironmentType[Environment.type],
1736
...properties

0 commit comments

Comments
 (0)