Skip to content

Commit 4670ec0

Browse files
committed
Adds some telemetry to start work flow
(#3621)
1 parent 93fcdc2 commit 4670ec0

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
@@ -304,6 +304,17 @@ export type TelemetryEvents = {
304304
duration: number;
305305
};
306306

307+
/** Sent when the user opens Start Work; use `instance` to correlate a StartWork "session" */
308+
'startWork/open': StartWorkEventDataBase;
309+
/** Sent when the launchpad is opened; use `instance` to correlate a StartWork "session" */
310+
'startWork/opened': StartWorkEventData & {
311+
connected: boolean;
312+
};
313+
/** 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" */
314+
'startWork/steps/connect': StartWorkEventData & {
315+
connected: boolean;
316+
};
317+
307318
/** Sent when a PR review was started in the inspect overview */
308319
openReviewMode: {
309320
provider: string;
@@ -441,6 +452,14 @@ export type CommandEventData =
441452
webview?: string;
442453
};
443454

455+
export type StartWorkTelemetryContext = StartWorkEventDataBase;
456+
457+
type StartWorkEventDataBase = {
458+
instance: number;
459+
};
460+
461+
type StartWorkEventData = StartWorkEventDataBase;
462+
444463
export type LaunchpadTelemetryContext = LaunchpadEventData;
445464

446465
type LaunchpadEventDataBase = {

src/plus/startWork/startWork.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ import { getSteps } from '../../commands/quickWizard.utils';
2020
import { proBadge } from '../../constants';
2121
import type { IntegrationId } from '../../constants.integrations';
2222
import { HostingIntegrationId } from '../../constants.integrations';
23+
import type { Source, Sources, StartWorkTelemetryContext } from '../../constants.telemetry';
2324
import type { Container } from '../../container';
2425
import type { SearchedIssue } from '../../git/models/issue';
2526
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
2627
import { createQuickPickItemOfT, createQuickPickSeparator } from '../../quickpicks/items/common';
2728
import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive';
2829
import { createDirectiveQuickPickItem, Directive, isDirectiveQuickPickItem } from '../../quickpicks/items/directive';
30+
import { getScopedCounter } from '../../system/counter';
2931
import { fromNow } from '../../system/date';
3032
import { some } from '../../system/iterable';
3133
import { configuration } from '../../system/vscode/configuration';
@@ -44,6 +46,7 @@ export type StartWorkResult = { items: StartWorkItem[] };
4446
interface Context {
4547
result: StartWorkResult;
4648
title: string;
49+
telemetryContext: StartWorkTelemetryContext | undefined;
4750
connectedIntegrations: Map<IntegrationId, boolean>;
4851
}
4952

@@ -58,6 +61,7 @@ export type StartWorkAction = 'start';
5861

5962
export interface StartWorkCommandArgs {
6063
readonly command: 'startWork';
64+
source?: Sources;
6165
}
6266

6367
function assertsStartWorkStepState(state: StepState<State>): asserts state is StartWorkStepState {
@@ -68,13 +72,23 @@ function assertsStartWorkStepState(state: StepState<State>): asserts state is St
6872
}
6973

7074
export const supportedStartWorkIntegrations = [HostingIntegrationId.GitHub];
75+
const instanceCounter = getScopedCounter();
7176

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

85+
this.source = { source: args?.source ?? 'commandPalette' };
86+
87+
if (this.container.telemetry.enabled) {
88+
this.telemetryContext = { instance: instanceCounter.next() };
89+
this.container.telemetry.sendEvent('startWork/open', { ...this.telemetryContext }, this.source);
90+
}
91+
7892
this.initialState = {
7993
counter: 0,
8094
};
@@ -88,14 +102,26 @@ export class StartWorkCommand extends QuickCommand<State> {
88102
const context: Context = {
89103
result: { items: [] },
90104
title: this.title,
105+
telemetryContext: this.telemetryContext,
91106
connectedIntegrations: await this.getConnectedIntegrations(),
92107
};
93108

109+
const opened = false;
94110
while (this.canStepsContinue(state)) {
95111
context.title = this.title;
96112

97113
const hasConnectedIntegrations = [...context.connectedIntegrations.values()].some(c => c);
98114
if (!hasConnectedIntegrations) {
115+
if (this.container.telemetry.enabled) {
116+
this.container.telemetry.sendEvent(
117+
opened ? 'startWork/steps/connect' : 'startWork/opened',
118+
{
119+
...context.telemetryContext!,
120+
connected: false,
121+
},
122+
this.source,
123+
);
124+
}
99125
const isUsingCloudIntegrations = configuration.get('cloudIntegrations.enabled', undefined, false);
100126
const result = isUsingCloudIntegrations
101127
? yield* this.confirmCloudIntegrationsConnectStep(state, context)

0 commit comments

Comments
 (0)