Skip to content

Commit a1f018b

Browse files
committed
address code review feedback
1 parent 59a5961 commit a1f018b

File tree

6 files changed

+285
-46
lines changed

6 files changed

+285
-46
lines changed

docs/src/content/docs/about/telemetry.mdx

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,29 @@ title: Telemetry
44

55
The SPFx Toolkit collects basic usage telemetry to help us understand how the extension is used and improve its features. We follow the VS Code Telemetry extension authors guide and use the recommended `@vscode/extension-telemetry` package to send anonymized telemetry data to Azure Application Insights.
66

7+
## Privacy and Data Protection
8+
9+
- All telemetry data is anonymized and does not contain personal information
10+
- No code, file paths, or project-specific data is collected
11+
- Data is used solely to understand feature usage and prioritize improvements
12+
- We comply with relevant privacy regulations and Microsoft's privacy policies
13+
- You can disable telemetry through VS Code's standard telemetry settings
14+
15+
## How to Disable Telemetry
16+
17+
To disable telemetry collection, you can use VS Code's built-in telemetry settings:
18+
1. Open VS Code Settings (File > Preferences > Settings)
19+
2. Search for "Telemetry"
20+
3. Set "Telemetry: Telemetry Level" to "off"
21+
22+
This will disable telemetry for all VS Code extensions that respect the standard telemetry settings, including the SharePoint Framework Toolkit.
23+
724
## What We Track
825

926
We collect anonymized usage data for the following actions:
1027

1128
### Actions View
29+
1230
- Create New Project
1331
- Add Component to Project
1432
- Upgrade Project
@@ -25,18 +43,32 @@ We collect anonymized usage data for the following actions:
2543
- Install Dependencies
2644

2745
### Tasks View
28-
- Build Project
29-
- Bundle Project
30-
- Clean Project
31-
- Deploy to Azure Storage
32-
- Package Project
33-
- Publish Project
34-
- Serve Project
35-
- Test Project
36-
- Trust Dev Cert
46+
47+
**Gulp Tasks:**
48+
- gulp build
49+
- gulp bundle
50+
- gulp clean
51+
- gulp package-solution
52+
- gulp serve
53+
- gulp test
54+
- gulp trust-dev-cert
55+
- gulp deploy-azure-storage
56+
57+
**Heft Tasks:**
58+
- heft build
59+
- heft clean
60+
- heft start
61+
- heft package
62+
- heft test
63+
- heft trust-dev-cert
64+
- heft deploy-azure-storage
65+
- heft eject
66+
67+
**NPM Scripts:**
3768
- Execute Terminal Command (for NPM scripts with script name tracking)
3869

3970
### App Management (Environment View)
71+
4072
- Add Tenant App Catalog
4173
- Add Site App Catalog
4274
- Remove Site App Catalog
@@ -53,24 +85,4 @@ We collect anonymized usage data for the following actions:
5385
- Remove Tenant Wide Extension
5486
- Enable Tenant Wide Extension
5587
- Disable Tenant Wide Extension
56-
- Update Tenant Wide Extension
57-
58-
### Authentication
59-
- Microsoft 365 login and logout actions
60-
61-
## Privacy and Data Protection
62-
63-
- All telemetry data is anonymized and does not contain personal information
64-
- No code, file paths, or project-specific data is collected
65-
- Data is used solely to understand feature usage and prioritize improvements
66-
- We comply with relevant privacy regulations and Microsoft's privacy policies
67-
- You can disable telemetry through VS Code's standard telemetry settings
68-
69-
## How to Disable Telemetry
70-
71-
To disable telemetry collection, you can use VS Code's built-in telemetry settings:
72-
1. Open VS Code Settings (File > Preferences > Settings)
73-
2. Search for "Telemetry"
74-
3. Set "Telemetry: Telemetry Level" to "off"
75-
76-
This will disable telemetry for all VS Code extensions that respect the standard telemetry settings, including the SharePoint Framework Toolkit.
88+
- Update Tenant Wide Extension

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
],
4747
"license": "MIT",
4848
"main": "./dist/extension.js",
49-
"aiConnectionString": "InstrumentationKey=137865b8-3555-4866-a2c9-7e35ead3d578;IngestionEndpoint=https://northeurope-2.in.applicationinsights.azure.com/;LiveEndpoint=https://northeurope.livediagnostics.monitor.azure.com/;ApplicationId=d253fe5b-d38c-41f5-841d-afed5bcd9557",
49+
"aiConnectionString": "",
5050
"contributes": {
5151
"chatParticipants": [
5252
{

src/extension.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,21 @@ export async function activate(context: vscode.ExtensionContext) {
5656
telemetryService = TelemetryService.getInstance();
5757
const packageJson = context.extension?.packageJSON;
5858
const connectionString = packageJson?.aiConnectionString;
59+
60+
const activationDuration = Date.now() - activationStartTime;
61+
5962
if (connectionString) {
6063
telemetryService.initialize(context, connectionString);
6164

62-
const activationDuration = Date.now() - activationStartTime;
63-
6465
telemetryService.sendEvent('Extension Activated', {
6566
version: context.extension.packageJSON.version,
6667
nodeVersion: process.version,
6768
platform: process.platform
6869
}, {
6970
activationTimeMs: activationDuration
7071
});
72+
} else {
73+
Logger.channel?.appendLine('No telemetry connection string configured.');
7174
}
7275

7376
scheduleFeedbackChecks(

src/providers/AuthProvider.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { TerminalCommandExecuter } from '../services/executeWrappers/TerminalCom
1212
import { isValidGUID } from '../utils/validateGuid';
1313
import { CliExecuter } from '../services/executeWrappers/CliCommandExecuter';
1414
import { EntraAppRegistration } from '../services/actions/EntraAppRegistration';
15-
import { TelemetryService } from '../utils/telemetry';
1615

1716

1817
export class M365AuthenticationSession implements AuthenticationSession {
@@ -53,10 +52,10 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
5352
);
5453

5554
subscriptions.push(
56-
commands.registerCommand(Commands.login, TelemetryService.withTelemetry(Commands.login, AuthProvider.signIn))
55+
commands.registerCommand(Commands.login, AuthProvider.signIn)
5756
);
5857
subscriptions.push(
59-
commands.registerCommand(Commands.logout, TelemetryService.withTelemetry(Commands.logout, AuthProvider.logout))
58+
commands.registerCommand(Commands.logout, AuthProvider.logout)
6059
);
6160
}
6261

src/utils/telemetry.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import { ExtensionContext, commands, env } from 'vscode';
1+
import { ExtensionContext, env } from 'vscode';
22
import { TelemetryReporter } from '@vscode/extension-telemetry';
33
import { Commands } from '../constants';
44

5-
export const TELEMETRY_EVENTS = {
6-
// accountTreeView
7-
[Commands.login]: 'Login',
8-
[Commands.logout]: 'Logout',
95

6+
export const TELEMETRY_EVENTS = {
107
// tasksTreeView
118
[Commands.gulpBuildProject]: 'Gulp Build Project',
129
[Commands.gulpBundleProject]: 'Gulp Bundle Project',
@@ -68,7 +65,7 @@ export const TELEMETRY_EVENTS = {
6865
export class TelemetryService {
6966
private static instance: TelemetryService;
7067
public reporter: TelemetryReporter | undefined;
71-
private static isInternalCall: boolean = false;
68+
private static activeExecutions: Set<string> = new Set();
7269

7370
private constructor() { }
7471

@@ -119,7 +116,10 @@ export class TelemetryService {
119116
return async (...args: any[]) => {
120117
const telemetryService = TelemetryService.getInstance();
121118

122-
if (telemetryService.reporter && !TelemetryService.isInternalCall) {
119+
// consider this an internal call if there are ANY active executions
120+
const isInternalCall = TelemetryService.activeExecutions.size > 0;
121+
122+
if (telemetryService.reporter && !isInternalCall) {
123123
const telemetryProperties: Record<string, string> = { ...properties };
124124

125125
// additional properties for npm scripts
@@ -133,12 +133,14 @@ export class TelemetryService {
133133
telemetryService.sendEvent(eventName, telemetryProperties, measurements);
134134
}
135135

136-
// to avoid twice tracking triggered by clean, build, bundle, etc. which internally calls executeTerminalCommand
137-
TelemetryService.isInternalCall = true;
136+
// Track this execution
137+
const executionId = Math.random().toString(36).substring(7);
138+
TelemetryService.activeExecutions.add(executionId);
139+
138140
try {
139141
return await originalCommand(...args);
140142
} finally {
141-
TelemetryService.isInternalCall = false;
143+
TelemetryService.activeExecutions.delete(executionId);
142144
}
143145
};
144146
}

0 commit comments

Comments
 (0)