Skip to content

Commit 76935bd

Browse files
committed
Adds graph command tracking
1 parent 6fa9c69 commit 76935bd

File tree

3 files changed

+59
-19
lines changed

3 files changed

+59
-19
lines changed

src/ai/aiProviderService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { CancellationToken, Disposable, MessageItem, ProgressOptions, QuickInputButton } from 'vscode';
22
import { env, ThemeIcon, Uri, window } from 'vscode';
33
import type { AIModels, AIProviders, SupportedAIModels } from '../constants.ai';
4-
import type { AIGenerateDraftEvent, Sources, TelemetryEvents } from '../constants.telemetry';
4+
import type { AIGenerateDraftEventData, Sources, TelemetryEvents } from '../constants.telemetry';
55
import type { Container } from '../container';
66
import { CancellationError } from '../errors';
77
import type { GitCommit } from '../git/models/commit';
@@ -285,7 +285,7 @@ export class AIProviderService implements Disposable {
285285

286286
async generateDraftMessage(
287287
changesOrRepoOrPath: string[] | Repository | Uri,
288-
sourceContext: { source: Sources; type: AIGenerateDraftEvent['draftType'] },
288+
sourceContext: { source: Sources; type: AIGenerateDraftEventData['draftType'] },
289289
options?: {
290290
cancellation?: CancellationToken;
291291
context?: string;

src/constants.telemetry.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ export type TelemetryEvents = {
9494
'ai/explain': {
9595
type: 'change';
9696
changeType: 'wip' | 'stash' | 'commit' | `draft-${'patch' | 'stash' | 'suggested_pr_change'}`;
97-
} & AIEventBase;
97+
} & AIEventDataBase;
9898

9999
/** Sent when generating summaries from commits, stashes, patches, etc. */
100-
'ai/generate': (AIGenerateCommitEvent | AIGenerateDraftEvent) & AIEventBase;
100+
'ai/generate': (AIGenerateCommitEventData | AIGenerateDraftEventData) & AIEventDataBase;
101101

102102
/** Sent when connecting to one or more cloud-based integrations*/
103103
'cloudIntegrations/connecting': {
@@ -193,19 +193,13 @@ export type TelemetryEvents = {
193193
};
194194

195195
/** Sent when a GitLens command is executed */
196-
command:
197-
| {
198-
command: Commands.GitCommands;
199-
context?: { mode?: string; submode?: string };
200-
}
201-
| {
202-
command: string;
203-
context?: undefined;
204-
webview?: string;
205-
};
196+
command: CommandEventData;
206197
/** Sent when a VS Code command is executed by a GitLens provided action */
207198
'command/core': { command: string };
208199

200+
/** Sent when a "Graph" command is executed */
201+
'graph/command': Omit<CommandEventData, 'context'>;
202+
209203
/** Sent when the user takes an action on a launchpad item */
210204
'launchpad/title/action': LaunchpadEventData & {
211205
action: 'feedback' | 'open-on-gkdev' | 'refresh' | 'settings' | 'connect';
@@ -389,7 +383,7 @@ export type TelemetryEvents = {
389383
};
390384
};
391385

392-
type AIEventBase = {
386+
type AIEventDataBase = {
393387
'model.id': AIModels;
394388
'model.provider.id': AIProviders;
395389
'model.provider.name': string;
@@ -401,15 +395,32 @@ type AIEventBase = {
401395
'failed.error'?: string;
402396
};
403397

404-
export type AIGenerateCommitEvent = {
398+
export type AIGenerateCommitEventData = {
405399
type: 'commitMessage';
406400
};
407401

408-
export type AIGenerateDraftEvent = {
402+
export type AIGenerateDraftEventData = {
409403
type: 'draftMessage';
410404
draftType: 'patch' | 'stash' | 'suggested_pr_change';
411405
};
412406

407+
export type CommandEventData =
408+
| {
409+
command: Commands.GitCommands;
410+
/** @deprecated Nested objects should not be used in telemetry */
411+
context?: { mode?: string; submode?: string };
412+
'context.mode'?: string;
413+
'context.submode'?: string;
414+
webview?: string;
415+
}
416+
| {
417+
command: string;
418+
context?: never;
419+
'context.mode'?: never;
420+
'context.submode'?: never;
421+
webview?: string;
422+
};
423+
413424
export type LaunchpadTelemetryContext = LaunchpadEventData;
414425

415426
type LaunchpadEventDataBase = {

src/system/vscode/command.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,22 @@ export function registerCommand(command: string, callback: CommandCallback, this
3232
}
3333
}
3434
}
35-
Container.instance.telemetry.sendEvent('command', { command: command, context: context });
35+
36+
Container.instance.telemetry.sendEvent('command', {
37+
command: command,
38+
context: context,
39+
'context.mode': context?.mode,
40+
'context.submode': context?.submode,
41+
});
42+
43+
if (command.startsWith('gitlens.graph.')) {
44+
Container.instance.telemetry.sendEvent('graph/command', {
45+
command: command,
46+
'context.mode': context?.mode,
47+
'context.submode': context?.submode,
48+
});
49+
}
50+
3651
callback.call(this, ...args);
3752
},
3853
thisArg,
@@ -43,10 +58,24 @@ export function registerWebviewCommand(command: string, callback: CommandCallbac
4358
return commands.registerCommand(
4459
command,
4560
function (this: any, ...args) {
61+
const webview = isWebviewContext(args[0]) ? args[0].webview : undefined;
62+
4663
Container.instance.telemetry.sendEvent('command', {
4764
command: command,
48-
webview: isWebviewContext(args[0]) ? args[0].webview : '<missing>',
65+
webview: webview ?? '<missing>',
4966
});
67+
68+
if (
69+
webview === 'gitlens.graph' ||
70+
webview === 'gitlens.views.graph' ||
71+
command.startsWith('gitlens.graph.')
72+
) {
73+
Container.instance.telemetry.sendEvent('graph/command', {
74+
command: command,
75+
webview: webview ?? '<missing>',
76+
});
77+
}
78+
5079
callback.call(this, ...args);
5180
},
5281
thisArg,

0 commit comments

Comments
 (0)