Skip to content

Commit 2901e44

Browse files
committed
Adds some telemetry to start work flow
(#3621)
1 parent f397c51 commit 2901e44

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

docs/telemetry-events.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,38 @@ void
13101310
}
13111311
```
13121312

1313+
### startWork/open
1314+
1315+
> Sent when the user opens Start Work; use `instance` to correlate a StartWork "session"
1316+
1317+
```typescript
1318+
{
1319+
'instance': number
1320+
}
1321+
```
1322+
1323+
### startWork/opened
1324+
1325+
> Sent when the launchpad is opened; use `instance` to correlate a StartWork "session"
1326+
1327+
```typescript
1328+
{
1329+
'instance': number,
1330+
'connected': false | true
1331+
}
1332+
```
1333+
1334+
### startWork/steps/connect
1335+
1336+
> 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"
1337+
1338+
```typescript
1339+
{
1340+
'instance': number,
1341+
'connected': false | true
1342+
}
1343+
```
1344+
13131345
### openReviewMode
13141346

13151347
> Sent when a PR review was started in the inspect overview

src/constants.telemetry.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,17 @@ export type TelemetryEvents = {
297297
duration: number;
298298
};
299299

300+
/** Sent when the user opens Start Work; use `instance` to correlate a StartWork "session" */
301+
'startWork/open': StartWorkEventDataBase;
302+
/** Sent when the launchpad is opened; use `instance` to correlate a StartWork "session" */
303+
'startWork/opened': StartWorkEventData & {
304+
connected: boolean;
305+
};
306+
/** 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" */
307+
'startWork/steps/connect': StartWorkEventData & {
308+
connected: boolean;
309+
};
310+
300311
/** Sent when a PR review was started in the inspect overview */
301312
openReviewMode: {
302313
provider: string;
@@ -446,6 +457,14 @@ export type CommandEventData =
446457
webview?: string;
447458
};
448459

460+
export type StartWorkTelemetryContext = StartWorkEventDataBase;
461+
462+
type StartWorkEventDataBase = {
463+
instance: number;
464+
};
465+
466+
type StartWorkEventData = StartWorkEventDataBase;
467+
449468
export type LaunchpadTelemetryContext = LaunchpadEventData;
450469

451470
type LaunchpadEventDataBase = {

src/plus/startWork/startWork.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ import { proBadge } from '../../constants';
2323
import { Commands } from '../../constants.commands';
2424
import type { IntegrationId } from '../../constants.integrations';
2525
import { HostingIntegrationId } from '../../constants.integrations';
26+
import type { Source, Sources, StartWorkTelemetryContext } from '../../constants.telemetry';
2627
import type { Container } from '../../container';
2728
import { PlusFeatures } from '../../features';
2829
import type { SearchedIssue } from '../../git/models/issue';
2930
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
3031
import { createQuickPickItemOfT, createQuickPickSeparator } from '../../quickpicks/items/common';
3132
import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive';
3233
import { createDirectiveQuickPickItem, Directive, isDirectiveQuickPickItem } from '../../quickpicks/items/directive';
34+
import { getScopedCounter } from '../../system/counter';
3335
import { fromNow } from '../../system/date';
3436
import { some } from '../../system/iterable';
3537
import { executeCommand } from '../../system/vscode/command';
@@ -48,6 +50,7 @@ export type StartWorkResult = { items: StartWorkItem[] };
4850
interface Context {
4951
result: StartWorkResult;
5052
title: string;
53+
telemetryContext: StartWorkTelemetryContext | undefined;
5154
connectedIntegrations: Map<IntegrationId, boolean>;
5255
}
5356

@@ -62,6 +65,7 @@ export type StartWorkAction = 'start';
6265

6366
export interface StartWorkCommandArgs {
6467
readonly command: 'startWork';
68+
source?: Sources;
6569
}
6670

6771
function assertsStartWorkStepState(state: StepState<State>): asserts state is StartWorkStepState {
@@ -72,13 +76,23 @@ function assertsStartWorkStepState(state: StepState<State>): asserts state is St
7276
}
7377

7478
export const supportedStartWorkIntegrations = [HostingIntegrationId.GitHub];
79+
const instanceCounter = getScopedCounter();
7580

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

89+
this.source = { source: args?.source ?? 'commandPalette' };
90+
91+
if (this.container.telemetry.enabled) {
92+
this.telemetryContext = { instance: instanceCounter.next() };
93+
this.container.telemetry.sendEvent('startWork/open', { ...this.telemetryContext }, this.source);
94+
}
95+
8296
this.initialState = {
8397
counter: 0,
8498
};
@@ -92,14 +106,26 @@ export class StartWorkCommand extends QuickCommand<State> {
92106
const context: Context = {
93107
result: { items: [] },
94108
title: this.title,
109+
telemetryContext: this.telemetryContext,
95110
connectedIntegrations: await this.getConnectedIntegrations(),
96111
};
97112

113+
const opened = false;
98114
while (this.canStepsContinue(state)) {
99115
context.title = this.title;
100116

101117
const hasConnectedIntegrations = [...context.connectedIntegrations.values()].some(c => c);
102118
if (!hasConnectedIntegrations) {
119+
if (this.container.telemetry.enabled) {
120+
this.container.telemetry.sendEvent(
121+
opened ? 'startWork/steps/connect' : 'startWork/opened',
122+
{
123+
...context.telemetryContext!,
124+
connected: false,
125+
},
126+
this.source,
127+
);
128+
}
103129
const result = yield* this.confirmCloudIntegrationsConnectStep(state, context);
104130
if (result === StepResultBreak) {
105131
return result;

0 commit comments

Comments
 (0)