Skip to content

Commit

Permalink
Adds graph command tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Sep 25, 2024
1 parent 6fa9c69 commit 76935bd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/ai/aiProviderService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CancellationToken, Disposable, MessageItem, ProgressOptions, QuickInputButton } from 'vscode';
import { env, ThemeIcon, Uri, window } from 'vscode';
import type { AIModels, AIProviders, SupportedAIModels } from '../constants.ai';
import type { AIGenerateDraftEvent, Sources, TelemetryEvents } from '../constants.telemetry';
import type { AIGenerateDraftEventData, Sources, TelemetryEvents } from '../constants.telemetry';
import type { Container } from '../container';
import { CancellationError } from '../errors';
import type { GitCommit } from '../git/models/commit';
Expand Down Expand Up @@ -285,7 +285,7 @@ export class AIProviderService implements Disposable {

async generateDraftMessage(
changesOrRepoOrPath: string[] | Repository | Uri,
sourceContext: { source: Sources; type: AIGenerateDraftEvent['draftType'] },
sourceContext: { source: Sources; type: AIGenerateDraftEventData['draftType'] },
options?: {
cancellation?: CancellationToken;
context?: string;
Expand Down
41 changes: 26 additions & 15 deletions src/constants.telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ export type TelemetryEvents = {
'ai/explain': {
type: 'change';
changeType: 'wip' | 'stash' | 'commit' | `draft-${'patch' | 'stash' | 'suggested_pr_change'}`;
} & AIEventBase;
} & AIEventDataBase;

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

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

/** Sent when a GitLens command is executed */
command:
| {
command: Commands.GitCommands;
context?: { mode?: string; submode?: string };
}
| {
command: string;
context?: undefined;
webview?: string;
};
command: CommandEventData;
/** Sent when a VS Code command is executed by a GitLens provided action */
'command/core': { command: string };

/** Sent when a "Graph" command is executed */
'graph/command': Omit<CommandEventData, 'context'>;

/** Sent when the user takes an action on a launchpad item */
'launchpad/title/action': LaunchpadEventData & {
action: 'feedback' | 'open-on-gkdev' | 'refresh' | 'settings' | 'connect';
Expand Down Expand Up @@ -389,7 +383,7 @@ export type TelemetryEvents = {
};
};

type AIEventBase = {
type AIEventDataBase = {
'model.id': AIModels;
'model.provider.id': AIProviders;
'model.provider.name': string;
Expand All @@ -401,15 +395,32 @@ type AIEventBase = {
'failed.error'?: string;
};

export type AIGenerateCommitEvent = {
export type AIGenerateCommitEventData = {
type: 'commitMessage';
};

export type AIGenerateDraftEvent = {
export type AIGenerateDraftEventData = {
type: 'draftMessage';
draftType: 'patch' | 'stash' | 'suggested_pr_change';
};

export type CommandEventData =
| {
command: Commands.GitCommands;
/** @deprecated Nested objects should not be used in telemetry */
context?: { mode?: string; submode?: string };
'context.mode'?: string;
'context.submode'?: string;
webview?: string;
}
| {
command: string;
context?: never;
'context.mode'?: never;
'context.submode'?: never;
webview?: string;
};

export type LaunchpadTelemetryContext = LaunchpadEventData;

type LaunchpadEventDataBase = {
Expand Down
33 changes: 31 additions & 2 deletions src/system/vscode/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,22 @@ export function registerCommand(command: string, callback: CommandCallback, this
}
}
}
Container.instance.telemetry.sendEvent('command', { command: command, context: context });

Container.instance.telemetry.sendEvent('command', {
command: command,
context: context,
'context.mode': context?.mode,
'context.submode': context?.submode,
});

if (command.startsWith('gitlens.graph.')) {
Container.instance.telemetry.sendEvent('graph/command', {
command: command,
'context.mode': context?.mode,
'context.submode': context?.submode,
});
}

callback.call(this, ...args);
},
thisArg,
Expand All @@ -43,10 +58,24 @@ export function registerWebviewCommand(command: string, callback: CommandCallbac
return commands.registerCommand(
command,
function (this: any, ...args) {
const webview = isWebviewContext(args[0]) ? args[0].webview : undefined;

Container.instance.telemetry.sendEvent('command', {
command: command,
webview: isWebviewContext(args[0]) ? args[0].webview : '<missing>',
webview: webview ?? '<missing>',
});

if (
webview === 'gitlens.graph' ||
webview === 'gitlens.views.graph' ||
command.startsWith('gitlens.graph.')
) {
Container.instance.telemetry.sendEvent('graph/command', {
command: command,
webview: webview ?? '<missing>',
});
}

callback.call(this, ...args);
},
thisArg,
Expand Down

0 comments on commit 76935bd

Please sign in to comment.