-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CHANGE @W-17526120@ Telemetry for A4D events #187
Conversation
bf9f8be
to
3764ed1
Compare
export type DiffAcceptDependencies = { | ||
callback: DiffAcceptCallback; | ||
telemetryService: TelemetryService; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any advantage of having this dependencies type instead of just passing in the telemetry service and callback directly into the constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The object keeps the invocation clean and means I don't have to worry about parameters. It also means we can make any of them optional without needing to reorder them or anything like that.
this.telemetryService.sendException(Constants.TELEM_DIFF_SUGGESTION_FAILED, errMsg, { | ||
executedCommand: this.commandName, | ||
duration: (Date.now() - startTime).toString() | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, what does this do? Where does the exception go?
And do we want to swallow this exception or rethrow it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sends a telemetry event indicating that we got an exception. I'm not entirely sure where they go, but we've already been doing this style of telemetry for when SFCA fails.
That said, you're almost certainly right that we should be rethrowing instead of swallowing, though in practice it's probably not terribly relevant because the accept/reject functionality should be pretty stable.
await this.callback(diffHunk); | ||
this.telemetryService.sendCommandEvent(Constants.TELEM_DIFF_REJECT, { | ||
commandName: this.commandName, | ||
commandSource: 'PLACEHOLDER', // DECIDE WHAT SHOULD GO HERE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at https://salesforce.quip.com/1ZgwAbICFda1 you'll see example commandSource values from other teams. My guess is we'll want to say something like SalesforceCodeAnalyzer or SFCA or something. Check with Joni Fazo.
Also I wonder how if we are missing anything else on this event. If you haven't done so already look through all the links in that doc which show how other teams are sending in the events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is one of the things I need to refine.
commandName: this.commandName, | ||
commandSource: 'PLACEHOLDER', // DECIDE WHAT SHOULD GO HERE | ||
completionNumLines: lines.toString(), | ||
languageType: 'apex' // Apex is the only language A4D codegen supports at present. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does CodeAnalyzer provide fixes for other languages? A4D supports all of the Salesforce languages today
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodeAnalyzer only supports callouts to A4D for a small handful of PMD rules, which are all Apex-based.
src/lib/constants.ts
Outdated
export const TELEM_DIFF_SUGGESTION_FAILED = 'sfdx__eGPT_suggest_failure'; | ||
export const TELEM_DIFF_ACCEPT = 'sfdx__eGPT_accept'; | ||
export const TELEM_DIFF_ACCEPT_FAILED = 'sfdx__eGPT_accept_failure'; | ||
export const TELEM_DIFF_REJECT = 'sfdx__eGPT_reject'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the team uses "sfdx__eGPT_clear" to track explicit rejections like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll switch to that.
@@ -28,6 +28,12 @@ export const TELEM_FAILED_STATIC_ANALYSIS = 'sfdx__codeanalyzer_static_run_faile | |||
export const TELEM_SUCCESSFUL_DFA_ANALYSIS = 'sfdx__codeanalyzer_dfa_run_complete'; | |||
export const TELEM_FAILED_DFA_ANALYSIS = 'sfdx__codeanalyzer_dfa_run_failed'; | |||
export const TELEM_SUCCESSFUL_APEX_GURU_FILE_ANALYSIS = 'sfdx__apexguru_file_run_complete'; | |||
export const TELEM_DIFF_SUGGESTION = 'sfdx__eGPT_suggest'; | |||
export const TELEM_DIFF_SUGGESTION_FAILED = 'sfdx__eGPT_suggest_failure'; | |||
export const TELEM_DIFF_ACCEPT = 'sfdx__eGPT_accept'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest we also fire out own accept events, as A4D has reasons for monitoring their telemetry, but it would be good to keep our telemetry events consistent as well
@@ -28,6 +28,12 @@ export const TELEM_FAILED_STATIC_ANALYSIS = 'sfdx__codeanalyzer_static_run_faile | |||
export const TELEM_SUCCESSFUL_DFA_ANALYSIS = 'sfdx__codeanalyzer_dfa_run_complete'; | |||
export const TELEM_FAILED_DFA_ANALYSIS = 'sfdx__codeanalyzer_dfa_run_failed'; | |||
export const TELEM_SUCCESSFUL_APEX_GURU_FILE_ANALYSIS = 'sfdx__apexguru_file_run_complete'; | |||
export const TELEM_DIFF_SUGGESTION = 'sfdx__eGPT_suggest'; | |||
export const TELEM_DIFF_SUGGESTION_FAILED = 'sfdx__eGPT_suggest_failure'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the failure states are usually bucketed under "sfdx__eGPT_error" but I'm not sure we need to inform A4D of anything other than accept events. For our own purposes, this would be good to log though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Realistically, any of these error cases actually happening is phenomenally low. I'm just programming a little defensively here.
ab4b34d
to
0cc20fe
Compare
try { | ||
const lines: number = await this.callback(diffHunk); | ||
this.telemetryService.sendCommandEvent(Constants.TELEM_DIFF_ACCEPT, { | ||
commandSource: this.commandName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this
commandSource: 'SFCA_A4D_FIX.' + this.commandName,
instead?
Ideally we should be sending the context which initiated the diff from our A4D quick fix button. That is, we should be updating this line:
https://github.com/forcedotcom/sfdx-code-analyzer-vscode/blob/dev/src/modelBasedFixers/apex-pmd-violations-fixer.ts#L86 with the 'SFCA_A4D_FIX' context to be sent to the callback of https://github.com/forcedotcom/sfdx-code-analyzer-vscode/blob/dev/src/extension.ts#L236
and from there you can pass in the 'SFCA_A4D_FIX' string to the DiffCreateAction constructor, and so forth.
try { | ||
await this.callback(code, file); | ||
this.telemetryService.sendCommandEvent(Constants.TELEM_DIFF_SUGGESTION, { | ||
commandSource: this.commandName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
private readonly telemetryService: TelemetryService; | ||
|
||
public constructor(commandName: string, dependencies: DiffRejectDependencies) { | ||
this.commandName = commandName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -83,12 +83,12 @@ export class ApexPmdViolationsFixer implements vscode.CodeActionProvider { | |||
|
|||
const updatedFileContent = this.replaceCodeInFile(document.getText(), codeSnippet.trim(), diagnostic.range.start.line + 1, diagnostic.range.end.line + 1, document); | |||
// Update the command arguments with the resolved code snippet | |||
codeAction.command.arguments = [updatedFileContent, document.uri]; | |||
codeAction.command.arguments = [updatedFileContent, document.uri, Constants.A4D_PREFIX]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't Constants.A4D_PREFIX be the first in the array given the callback is:
vscode.commands.registerCommand(Constants.UNIFIED_DIFF, async (source: string, code: string, file?: string) => {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, yeah.
No description provided.