Skip to content

Commit 0775549

Browse files
committed
Added telemetry iKey check
1 parent fe885b4 commit 0775549

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/common/appInsights/index.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { version } from './version';
33
import {Environment,EnvironmentType} from "@microsoft/sp-core-library";
44

55
const controlType = "react";
6+
const iKey = "9f59b81e-d2ed-411e-a961-8bcf3f7f04d0";
67

78
if (typeof AppInsights !== "undefined") {
89
AppInsights.downloadAndSetup({
9-
instrumentationKey: "9f59b81e-d2ed-411e-a961-8bcf3f7f04d0",
10+
instrumentationKey: iKey,
1011
disableExceptionTracking: true,
1112
disableAjaxTracking: true
1213
});
@@ -21,20 +22,23 @@ if (typeof appInsights !== "undefined") {
2122

2223
// Filter out telemetry data
2324
appInsights.context.addTelemetryInitializer((envelope: Microsoft.ApplicationInsights.IEnvelope) => {
24-
const telemetryItem = envelope.data.baseData;
25-
// Only send telemetry data if it contains data of this library
26-
if (!telemetryItem.properties || !telemetryItem.properties.controlType) {
27-
return false;
28-
}
25+
// Only run this telemetry initializer for the PnP controls
26+
if (envelope.iKey === iKey) {
27+
const telemetryItem = envelope.data.baseData;
28+
// Only send telemetry data if it contains data of this library
29+
if (!telemetryItem.properties || !telemetryItem.properties.controlType) {
30+
return false;
31+
}
2932

30-
// Check if the type of data is only EventData, otherwise this may not be sent
31-
if (envelope.data && envelope.data.baseType !== "EventData") {
32-
return false;
33-
}
33+
// Check if the type of data is only EventData, otherwise this may not be sent
34+
if (envelope.data && envelope.data.baseType !== "EventData") {
35+
return false;
36+
}
3437

35-
// Only send telemetry if it is coming from the right control type
36-
if (telemetryItem.properties && telemetryItem.properties.controlType && telemetryItem.properties.controlType !== controlType) {
37-
return false;
38+
// Only send telemetry if it is coming from the right control type
39+
if (telemetryItem.properties && telemetryItem.properties.controlType && telemetryItem.properties.controlType !== controlType) {
40+
return false;
41+
}
3842
}
3943
});
4044
});

0 commit comments

Comments
 (0)