Skip to content

Commit 024bdab

Browse files
authored
Merge pull request #41 from DeepCodeAI/report_suggestion_view
Report telemetry events
2 parents e56eadc + 7fca794 commit 024bdab

14 files changed

Lines changed: 160 additions & 44 deletions

File tree

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@
6363
"default": false,
6464
"markdownDescription": "User consent for code upload to `#deepcode.url#`",
6565
"scope": "window"
66+
},
67+
"deepcode.yesCrashReport": {
68+
"//": "Name starts with y to put it at the end, as configs are sorted alphbetically",
69+
"type": "boolean",
70+
"default": true,
71+
"markdownDescription": "Allow crash reports to be reported to `#deepcode.url#`",
72+
"scope": "application"
73+
},
74+
"deepcode.yesTelemetry": {
75+
"//": "Name starts with y to put it at the end, as configs are sorted alphbetically",
76+
"type": "boolean",
77+
"default": true,
78+
"markdownDescription": "Allow extension's telemetry to be sent to `#deepcode.url#`",
79+
"scope": "application"
6680
}
6781
}
6882
}
@@ -103,6 +117,6 @@
103117
"ignore": "^5.1.4",
104118
"mz": "^2.7.0",
105119
"open": "^7.0.0",
106-
"@deepcode/tsc": "^1.1.0"
120+
"@deepcode/tsc": "^1.3.0"
107121
}
108122
}

src/deepcode/DeepCodeExtension.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
1111
this.store.createStore(context);
1212
this.statusBarItem.show();
1313

14-
context.subscriptions.push(
14+
context.subscriptions.push(
1515
vscode.commands.registerCommand(
1616
DEEPCODE_START_COMMAND,
1717
this.activateExtensionAnalyzeActions.bind(this)
1818
)
1919
);
2020

21-
context.subscriptions.push(
21+
context.subscriptions.push(
2222
vscode.commands.registerCommand(
2323
DEEPCODE_SETTINGS_COMMAND,
2424
openDeepcodeSettingsCommand
2525
)
2626
);
27-
27+
2828
context.subscriptions.push(
2929
{ dispose: this.startExtension() },
3030
);
@@ -43,7 +43,7 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
4343
}
4444

4545
public startExtension(): any {
46-
this.activateWatchers();
46+
this.activateAll();
4747
this.activateExtensionAnalyzeActions();
4848
}
4949

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const TELEMETRY_EVENTS = {
2+
ignoreSuggestion: 'ignoreSuggestion',
3+
viewSuggestion: 'viewSuggestion',
4+
};

src/deepcode/http/requests.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { IDE_NAME } from "../constants/general";
88
const AI = new ServiceAI();
99

1010
const http = {
11-
11+
1212
login(baseURL: string, source: string = IDE_NAME): Promise<any> {
1313
return AI.startSession({ baseURL, source });
1414
},
@@ -35,11 +35,19 @@ const http = {
3535
});
3636
},
3737

38-
// TODO: when API package will implement such functionality
39-
// we would have the possibility to send an error to server
40-
async sendError(body: any): Promise<void> {
41-
return Promise.resolve();
42-
}
38+
async sendError(baseURL: string, options: {[key: string]: any}): Promise<any> {
39+
return AI.reportError({
40+
baseURL,
41+
...options
42+
});
43+
},
44+
45+
async sendEvent(baseURL: string, options: {[key: string]: any}): Promise<any> {
46+
return AI.reportEvent({
47+
baseURL,
48+
...options,
49+
});
50+
},
4351
};
4452

4553
export default http;

src/deepcode/lib/analyzer/DeepCodeAnalyzer.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import {
66
createIssuesMarkersDecorationOptions,
77
createIssueRelatedInformation,
88
createDeepCodeSeveritiesMap,
9+
getDeepCodeSeverity,
910
extractSuggestionIdFromSuggestionsMap
1011
} from "../../utils/analysisUtils";
1112
import { DEEPCODE_NAME } from "../../constants/general";
13+
import { TELEMETRY_EVENTS } from "../../constants/telemetry";
1214
import { ISSUES_MARKERS_DECORATION_TYPE } from "../../constants/analysis";
1315
import { deepCodeMessages } from "../../messages/deepCodeMessages";
1416
import { errorsLogs } from "../../messages/errorsServerLogMessages";
@@ -20,6 +22,7 @@ class DeepCodeAnalyzer implements DeepCode.AnalyzerInterface {
2022
private SEVERITIES: {
2123
[key: number]: { name: vscode.DiagnosticSeverity; show: boolean };
2224
};
25+
private extension: DeepCode.ExtensionInterface | undefined;
2326
private analysisProgressValue: number = 1; // default value for progress to make it visible from start
2427
private progress = vscode.window.withProgress;
2528
private analysisInProgress: boolean = false;
@@ -41,18 +44,34 @@ class DeepCodeAnalyzer implements DeepCode.AnalyzerInterface {
4144
{
4245
findSuggestionId: extractSuggestionIdFromSuggestionsMap(
4346
this.analysisResultsCollection
44-
)
47+
),
48+
trackIgnoreSuggestion: this.trackIgnoreSuggestion.bind(this)
4549
}
4650
);
4751
this.issueHoverProvider = new DisposableHoverProvider(this.deepcodeReview);
4852
}
4953

54+
public activate(extension: DeepCode.ExtensionInterface) {
55+
this.extension = extension;
56+
}
57+
58+
public trackIgnoreSuggestion(vscodeSeverity: number, options: {[key: string]: any}): void {
59+
if (!this.extension) return;
60+
options.data = {
61+
severity: getDeepCodeSeverity(vscodeSeverity),
62+
...options.data
63+
};
64+
this.extension.sendEvent(
65+
TELEMETRY_EVENTS.ignoreSuggestion,
66+
options
67+
);
68+
}
5069

5170
public updateAnalysisResultsCollection(results: DeepCode.AnalysisResultsCollectionInterface, rootPath: string): void {
5271
this.analysisResultsCollection[rootPath] = {...results} as unknown as DeepCode.AnalysisResultsInterface;
5372
this.createReviewResults();
5473
}
55-
74+
5675
private createIssueDiagnosticInfo({
5776
issue,
5877
issuePositions,

src/deepcode/lib/deepCodeProviders/codeActionsProvider/DeepCodeIssuesActionsProvider.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class DeepCodeIssuesActionProvider implements vscode.CodeActionProvider {
2121

2222
private issuesList: vscode.DiagnosticCollection | undefined;
2323
private findSuggestionId: Function;
24+
private trackIgnoreSuggestion: Function;
2425

2526
constructor(
2627
issuesList: vscode.DiagnosticCollection | undefined,
@@ -29,6 +30,7 @@ export class DeepCodeIssuesActionProvider implements vscode.CodeActionProvider {
2930
this.issuesList = issuesList;
3031
this.registerIgnoreIssuesCommand();
3132
this.findSuggestionId = callbacks.findSuggestionId;
33+
this.trackIgnoreSuggestion = callbacks.trackIgnoreSuggestion;
3234
}
3335

3436
private registerIgnoreIssuesCommand() {
@@ -37,12 +39,23 @@ export class DeepCodeIssuesActionProvider implements vscode.CodeActionProvider {
3739
({
3840
currentEditor,
3941
issueText,
40-
matchedIssue
42+
matchedIssue,
43+
issueId,
44+
isFileIgnore,
4145
}: {
4246
currentEditor: vscode.TextEditor;
4347
matchedIssue: vscode.Diagnostic;
4448
issueText: string;
49+
issueId: string;
50+
isFileIgnore?: boolean;
4551
}): void => {
52+
this.trackIgnoreSuggestion(matchedIssue.severity, {
53+
message: matchedIssue.message,
54+
data: {
55+
issueId,
56+
isFileIgnore: !!isFileIgnore,
57+
}
58+
});
4659
const editor: vscode.TextEditor | undefined =
4760
currentEditor || vscode.window.activeTextEditor;
4861
if (!editor || !issueText || !matchedIssue) {
@@ -135,11 +148,10 @@ export class DeepCodeIssuesActionProvider implements vscode.CodeActionProvider {
135148
issueNameForComment,
136149
isFileIgnore
137150
);
138-
139151
ignoreIssueAction.command = {
140152
command: DEEPCODE_IGNORE_ISSUES_COMMAND,
141153
title: DEEPCODE_IGNORE_ISSUES_COMMAND,
142-
arguments: [{ issueText, matchedIssue }]
154+
arguments: [{ issueText, matchedIssue, issueId: issueFullId, isFileIgnore }]
143155
};
144156

145157
return ignoreIssueAction;

src/deepcode/lib/errorHandler/DeepCodeErrorHandler.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DeepCodeErrorHandler implements DeepCode.ErrorHandlerInterface {
2929
private async serverErrorHandler(extension: DeepCode.ExtensionInterface | any): Promise<void> {
3030
const { msg } = deepCodeMessages.noConnection;
3131
vscode.window.showErrorMessage(msg);
32-
32+
3333
setTimeout(async () => {
3434
startDeepCodeCommand();
3535
}, 5000);
@@ -86,20 +86,18 @@ class DeepCodeErrorHandler implements DeepCode.ErrorHandlerInterface {
8686
error: DeepCode.errorType,
8787
options: { [key: string]: any }
8888
): Promise<void> {
89-
if (process.env.NODE_ENV === "production") {
90-
// please disable request sending in dev mode to avoid unnecessary reports to server
91-
await http.sendError({
92-
//for testing edpoint use source: 'test'
93-
source: IDE_NAME,
89+
await extension.sendError(
90+
{
9491
type: `${error.statusCode || ""} ${error.name || ""}`.trim(),
95-
errorTrace: JSON.stringify(error),
9692
message: options.message || errorsLogs.undefinedError,
97-
...(extension.token && { sessionToken: extension.token }),
9893
...(options.endpoint && { path: options.endpoint }),
9994
...(options.bundleId && { bundleId: options.bundleId }),
100-
...(options.data && { data: options.data })
101-
});
102-
}
95+
data: {
96+
errorTrace: JSON.stringify(error),
97+
...options.data
98+
}
99+
}
100+
);
103101
}
104102

105103
private async unauthorizedAccess(extension: DeepCode.ExtensionInterface): Promise<void> {

src/deepcode/lib/modules/BaseDeepCodeModule.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleIn
6767
}
6868

6969
public get source(): string {
70-
return process.env['GITPOD_WORKSPACE_ID'] ? 'gitpod' : IDE_NAME;
70+
return process.env['GITPOD_WORKSPACE_ID'] ? 'gitpod' : IDE_NAME;
7171
}
7272

7373
public get uploadApproved(): boolean {
@@ -77,5 +77,12 @@ export default class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleIn
7777
public async approveUpload(isGlobal: boolean = false): Promise<void> {
7878
await vscode.workspace.getConfiguration('deepcode').update('uploadApproved', true, isGlobal);
7979
}
80-
80+
81+
public get shouldReportErrors(): boolean {
82+
return !!vscode.workspace.getConfiguration('deepcode').get('yesCrashReport');
83+
}
84+
85+
public get shouldReportEvents(): boolean {
86+
return !!vscode.workspace.getConfiguration('deepcode').get('yesTelemetry');
87+
}
8188
}

src/deepcode/lib/modules/DeepCodeLib.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import BundlesModule from "./BundlesModule";
55

66
export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepCodeLibInterface {
77

8-
public activateWatchers(): void {
8+
public activateAll(): void {
99
this.filesWatcher.activate(this);
1010
this.workspacesWatcher.activate(this);
1111
this.editorsWatcher.activate(this);
1212
this.settingsWatcher.activate(this);
13+
this.analyzer.activate(this);
1314
}
1415

1516

@@ -43,12 +44,12 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
4344

4445
if (this.workspacesPaths.length) {
4546
this.updateCurrentWorkspacePath(this.workspacesPaths[0]);
46-
47+
4748
await this.updateHashesBundles();
4849

4950
// Third, initiate analysis
5051
try {
51-
// Main entry point to
52+
// Main entry point to
5253
for await (const path of this.workspacesPaths) {
5354
await this.performBundlesActions(path);
5455
}

0 commit comments

Comments
 (0)