Skip to content

Commit

Permalink
feat: add configuration to enable analytics reporting
Browse files Browse the repository at this point in the history
Introduced `yesAnalyticsReport` flag to allow users to opt-in or opt-out of analytics reporting.
This setting is added to `package.json` for visibility in VS Code UI and integrated into the `IConfiguration` interface.
  • Loading branch information
cat2608 committed Nov 18, 2023
1 parent e28a6ff commit 85b1d0e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
{
"title": "Snyk Security - Code and Open Source Dependencies",
"properties": {
"snyk.yesAnalyticsReport": {
"//": "Name starts with y to put it at the end, as configs are sorted alphbetically",
"type": "boolean",
"default": true,
"markdownDescription": "Send usage statistics to Snyk",
"scope": "application"
},
"snyk.yesCrashReport": {
"//": "Name starts with y to put it at the end, as configs are sorted alphbetically",
"type": "boolean",
Expand Down
18 changes: 18 additions & 0 deletions src/snyk/common/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
SCANNING_MODE,
SEVERITY_FILTER_SETTING,
TRUSTED_FOLDERS,
YES_ANALYTICS_REPORT,
YES_BACKGROUND_OSS_NOTIFICATION_SETTING,
YES_CRASH_REPORT_SETTING,
YES_TELEMETRY_SETTING,
Expand Down Expand Up @@ -81,6 +82,7 @@ export interface IConfiguration {

shouldReportErrors: boolean;
shouldReportEvents: boolean;
shouldReportAnalytics: boolean;
shouldShowWelcomeNotification: boolean;

hideWelcomeNotification(): Promise<void>;
Expand Down Expand Up @@ -342,6 +344,22 @@ export class Configuration implements IConfiguration {
);
}

get shouldReportAnalytics(): boolean {
return !!this.workspace.getConfiguration<boolean>(
CONFIGURATION_IDENTIFIER,
this.getConfigName(YES_ANALYTICS_REPORT),
);
}

async setShouldReportAnalytics(yesAnalyticsReport: boolean): Promise<void> {
await this.workspace.updateConfiguration(
CONFIGURATION_IDENTIFIER,
this.getConfigName(YES_ANALYTICS_REPORT),
yesAnalyticsReport,
true,
);
}

get shouldReportErrors(): boolean {
return !!this.workspace.getConfiguration<boolean>(
CONFIGURATION_IDENTIFIER,
Expand Down
1 change: 1 addition & 0 deletions src/snyk/common/constants/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const YES_CRASH_REPORT_SETTING = `${CONFIGURATION_IDENTIFIER}.yesCrashRep
export const YES_TELEMETRY_SETTING = `${CONFIGURATION_IDENTIFIER}.yesTelemetry`;
export const YES_WELCOME_NOTIFICATION_SETTING = `${CONFIGURATION_IDENTIFIER}.yesWelcomeNotification`;
export const YES_BACKGROUND_OSS_NOTIFICATION_SETTING = `${CONFIGURATION_IDENTIFIER}.yesBackgroundOssNotification`;
export const YES_ANALYTICS_REPORT = `${CONFIGURATION_IDENTIFIER}.yesAnalyticsReport`;

export const ADVANCED_ADVANCED_MODE_SETTING = `${CONFIGURATION_IDENTIFIER}.advanced.advancedMode`;
export const ADVANCED_AUTOSCAN_OSS_SETTING = `${CONFIGURATION_IDENTIFIER}.advanced.autoScanOpenSourceSecurity`;
Expand Down
2 changes: 2 additions & 0 deletions src/snyk/common/languageServer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type ServerSettings = {
// Reporting and telemetry
sendErrorReports?: string;
enableTelemetry?: string;
enableAnalytics?: boolean;

// Security and scanning settings
filterSeverity?: SeverityFilter;
Expand Down Expand Up @@ -78,6 +79,7 @@ export class LanguageServerSettings {

sendErrorReports: `${configuration.shouldReportErrors}`,
enableTelemetry: `${configuration.shouldReportEvents}`,
enableAnalytics: configuration.shouldReportAnalytics,

filterSeverity: configuration.severityFilter,
scanningMode: configuration.scanningMode,
Expand Down
2 changes: 2 additions & 0 deletions src/test/unit/common/languageServer/languageServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ suite('Language Server', () => {
},
shouldReportEvents: true,
shouldReportErrors: true,
shouldReportAnalytics: true,
getSnykLanguageServerPath(): string {
return path;
},
Expand Down Expand Up @@ -206,6 +207,7 @@ suite('Language Server', () => {
token: 'testToken',
cliPath: 'testPath',
enableTelemetry: 'true',
enableAnalytics: true,
sendErrorReports: 'true',
integrationName: 'VS_CODE',
integrationVersion: '0.0.0',
Expand Down
3 changes: 3 additions & 0 deletions src/test/unit/common/languageServer/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ suite('LanguageServerSettings', () => {
const mockConfiguration: IConfiguration = {
shouldReportEvents: true,
shouldReportErrors: false,
shouldReportAnalytics: true,
snykOssApiEndpoint: 'https://dev.snyk.io/api',
organization: 'my-org',
// eslint-disable-next-line @typescript-eslint/require-await
Expand All @@ -47,6 +48,8 @@ suite('LanguageServerSettings', () => {

assert.strictEqual(serverSettings.enableTelemetry, 'true');
assert.strictEqual(serverSettings.sendErrorReports, 'false');
assert.strictEqual(serverSettings.enableAnalytics, true);

assert.strictEqual(serverSettings.cliPath, '/path/to/cli');

assert.strictEqual(serverSettings.token, 'snyk-token');
Expand Down

0 comments on commit 85b1d0e

Please sign in to comment.