Skip to content

Commit

Permalink
Adds some telemetry to start work flow
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeibbb committed Oct 24, 2024
1 parent a3e608b commit c90e4d5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
34 changes: 33 additions & 1 deletion docs/telemetry-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,38 @@ void
}
```

### startWork/open

> Sent when the user opens Start Work; use `instance` to correlate a StartWork "session"
```typescript
{
'instance': number
}
```

### startWork/opened

> Sent when the launchpad is opened; use `instance` to correlate a StartWork "session"
```typescript
{
'instance': number,
'connected': false | true
}
```

### startWork/steps/connect

> Sent when the Start Work has "reloaded" (while open, e.g. user refreshed or back button) and is disconnected; use `instance` to correlate a Start Work "session"
```typescript
{
'instance': number,
'connected': false | true
}
```

### openReviewMode

> Sent when a PR review was started in the inspect overview
Expand All @@ -1320,7 +1352,7 @@ void
'repository.visibility': 'private' | 'public' | 'local',
'repoPrivacy': 'private' | 'public' | 'local',
'filesChanged': number,
'source': 'graph' | 'patchDetails' | 'settings' | 'timeline' | 'welcome' | 'home' | 'code-suggest' | 'account' | 'cloud-patches' | 'commandPalette' | 'deeplink' | 'inspect' | 'inspect-overview' | 'integrations' | 'launchpad' | 'launchpad-indicator' | 'launchpad-view' | 'notification' | 'prompt' | 'quick-wizard' | 'remoteProvider' | 'trial-indicator' | 'scm-input' | 'subscription' | 'walkthrough' | 'worktrees'
'source': 'graph' | 'patchDetails' | 'settings' | 'timeline' | 'welcome' | 'home' | 'code-suggest' | 'account' | 'cloud-patches' | 'commandPalette' | 'deeplink' | 'inspect' | 'inspect-overview' | 'integrations' | 'launchpad' | 'launchpad-indicator' | 'launchpad-view' | 'notification' | 'prompt' | 'quick-wizard' | 'remoteProvider' | 'startWork' | 'trial-indicator' | 'scm-input' | 'subscription' | 'walkthrough' | 'worktrees'
}
```

Expand Down
20 changes: 20 additions & 0 deletions src/constants.telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,17 @@ export type TelemetryEvents = {
duration: number;
};

/** Sent when the user opens Start Work; use `instance` to correlate a StartWork "session" */
'startWork/open': StartWorkEventDataBase;
/** Sent when the launchpad is opened; use `instance` to correlate a StartWork "session" */
'startWork/opened': StartWorkEventData & {
connected: boolean;
};
/** Sent when the Start Work has "reloaded" (while open, e.g. user refreshed or back button) and is disconnected; use `instance` to correlate a Start Work "session" */
'startWork/steps/connect': StartWorkEventData & {
connected: boolean;
};

/** Sent when a PR review was started in the inspect overview */
openReviewMode: {
provider: string;
Expand Down Expand Up @@ -446,6 +457,14 @@ export type CommandEventData =
webview?: string;
};

export type StartWorkTelemetryContext = StartWorkEventDataBase;

type StartWorkEventDataBase = {
instance: number;
};

type StartWorkEventData = StartWorkEventDataBase;

export type LaunchpadTelemetryContext = LaunchpadEventData;

type LaunchpadEventDataBase = {
Expand Down Expand Up @@ -611,6 +630,7 @@ export type Sources =
| 'quick-wizard'
| 'remoteProvider'
| 'settings'
| 'startWork'
| 'timeline'
| 'trial-indicator'
| 'scm-input'
Expand Down
29 changes: 28 additions & 1 deletion src/plus/startWork/startWork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ import { proBadge } from '../../constants';
import { Commands } from '../../constants.commands';
import type { IntegrationId } from '../../constants.integrations';
import { HostingIntegrationId } from '../../constants.integrations';
import type { Source, Sources, StartWorkTelemetryContext } from '../../constants.telemetry';
import type { Container } from '../../container';
import { PlusFeatures } from '../../features';
import type { SearchedIssue } from '../../git/models/issue';
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
import { createQuickPickItemOfT, createQuickPickSeparator } from '../../quickpicks/items/common';
import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive';
import { createDirectiveQuickPickItem, Directive, isDirectiveQuickPickItem } from '../../quickpicks/items/directive';
import { getScopedCounter } from '../../system/counter';
import { fromNow } from '../../system/date';
import { some } from '../../system/iterable';
import { executeCommand } from '../../system/vscode/command';
Expand All @@ -49,6 +51,7 @@ export type StartWorkResult = { items: StartWorkItem[] };
interface Context {
result: StartWorkResult;
title: string;
telemetryContext: StartWorkTelemetryContext | undefined;
connectedIntegrations: Map<IntegrationId, boolean>;
}

Expand All @@ -63,6 +66,7 @@ export type StartWorkAction = 'start';

export interface StartWorkCommandArgs {
readonly command: 'startWork';
source?: Sources;
}

function assertsStartWorkStepState(state: StepState<State>): asserts state is StartWorkStepState {
Expand All @@ -72,12 +76,23 @@ function assertsStartWorkStepState(state: StepState<State>): asserts state is St
throw new Error('Missing item');
}

const instanceCounter = getScopedCounter();

export class StartWorkCommand extends QuickCommand<State> {
constructor(container: Container) {
private readonly source: Source;
private readonly telemetryContext: StartWorkTelemetryContext | undefined;
constructor(container: Container, args?: StartWorkCommandArgs) {
super(container, 'startWork', 'startWork', `Start Work\u00a0\u00a0${proBadge}`, {
description: 'Start work on an issue',
});

this.source = { source: args?.source ?? 'commandPalette' };

if (this.container.telemetry.enabled) {
this.telemetryContext = { instance: instanceCounter.next() };
this.container.telemetry.sendEvent('startWork/open', { ...this.telemetryContext }, this.source);
}

this.initialState = {
counter: 0,
};
Expand All @@ -91,14 +106,26 @@ export class StartWorkCommand extends QuickCommand<State> {
const context: Context = {
result: { items: [] },
title: this.title,
telemetryContext: this.telemetryContext,
connectedIntegrations: await this.container.startWork.getConnectedIntegrations(),
};

const opened = false;
while (this.canStepsContinue(state)) {
context.title = this.title;

const hasConnectedIntegrations = [...context.connectedIntegrations.values()].some(c => c);
if (!hasConnectedIntegrations) {
if (this.container.telemetry.enabled) {
this.container.telemetry.sendEvent(
opened ? 'startWork/steps/connect' : 'startWork/opened',
{
...context.telemetryContext!,
connected: false,
},
this.source,
);
}
const result = yield* this.confirmCloudIntegrationsConnectStep(state, context);
if (result === StepResultBreak) {
return result;
Expand Down

0 comments on commit c90e4d5

Please sign in to comment.