Skip to content

Commit 33fad37

Browse files
committed
Adds some telemetry to start work flow
(#3621, #3698)
1 parent e21b34a commit 33fad37

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
@@ -1321,6 +1321,38 @@ void
13211321
}
13221322
```
13231323

1324+
### startWork/open
1325+
1326+
> Sent when the user opens Start Work; use `instance` to correlate a StartWork "session"
1327+
1328+
```typescript
1329+
{
1330+
'instance': number
1331+
}
1332+
```
1333+
1334+
### startWork/opened
1335+
1336+
> Sent when the launchpad is opened; use `instance` to correlate a StartWork "session"
1337+
1338+
```typescript
1339+
{
1340+
'instance': number,
1341+
'connected': false | true
1342+
}
1343+
```
1344+
1345+
### startWork/steps/connect
1346+
1347+
> 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"
1348+
1349+
```typescript
1350+
{
1351+
'instance': number,
1352+
'connected': false | true
1353+
}
1354+
```
1355+
13241356
### openReviewMode
13251357

13261358
> 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
@@ -311,6 +311,17 @@ export type TelemetryEvents = {
311311
duration: number;
312312
};
313313

314+
/** Sent when the user opens Start Work; use `instance` to correlate a StartWork "session" */
315+
'startWork/open': StartWorkEventDataBase;
316+
/** Sent when the launchpad is opened; use `instance` to correlate a StartWork "session" */
317+
'startWork/opened': StartWorkEventData & {
318+
connected: boolean;
319+
};
320+
/** 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" */
321+
'startWork/steps/connect': StartWorkEventData & {
322+
connected: boolean;
323+
};
324+
314325
/** Sent when a PR review was started in the inspect overview */
315326
openReviewMode: {
316327
provider: string;
@@ -451,6 +462,14 @@ export type CommandEventData =
451462
webview?: string;
452463
};
453464

465+
export type StartWorkTelemetryContext = StartWorkEventDataBase;
466+
467+
type StartWorkEventDataBase = {
468+
instance: number;
469+
};
470+
471+
type StartWorkEventData = StartWorkEventDataBase;
472+
454473
export type LaunchpadTelemetryContext = LaunchpadEventData;
455474

456475
type LaunchpadEventDataBase = {

src/plus/startWork/startWork.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ import {
1919
import { proBadge } from '../../constants';
2020
import type { IntegrationId } from '../../constants.integrations';
2121
import { HostingIntegrationId } from '../../constants.integrations';
22+
import type { Source, Sources, StartWorkTelemetryContext } from '../../constants.telemetry';
2223
import type { Container } from '../../container';
2324
import type { SearchedIssue } from '../../git/models/issue';
2425
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
2526
import { createQuickPickItemOfT } from '../../quickpicks/items/common';
2627
import { createDirectiveQuickPickItem, Directive } from '../../quickpicks/items/directive';
28+
import { getScopedCounter } from '../../system/counter';
2729
import { fromNow } from '../../system/date';
2830
import { some } from '../../system/iterable';
2931
import { configuration } from '../../system/vscode/configuration';
@@ -37,6 +39,7 @@ export type StartWorkResult = { items: StartWorkItem[] };
3739
interface Context {
3840
result: StartWorkResult;
3941
title: string;
42+
telemetryContext: StartWorkTelemetryContext | undefined;
4043
connectedIntegrations: Map<IntegrationId, boolean>;
4144
}
4245

@@ -51,6 +54,7 @@ export type StartWorkAction = 'start';
5154

5255
export interface StartWorkCommandArgs {
5356
readonly command: 'startWork';
57+
source?: Sources;
5458
}
5559

5660
function assertsStartWorkStepState(state: StepState<State>): asserts state is StartWorkStepState {
@@ -61,13 +65,23 @@ function assertsStartWorkStepState(state: StepState<State>): asserts state is St
6165
}
6266

6367
export const supportedStartWorkIntegrations = [HostingIntegrationId.GitHub];
68+
const instanceCounter = getScopedCounter();
6469

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

78+
this.source = { source: args?.source ?? 'commandPalette' };
79+
80+
if (this.container.telemetry.enabled) {
81+
this.telemetryContext = { instance: instanceCounter.next() };
82+
this.container.telemetry.sendEvent('startWork/open', { ...this.telemetryContext }, this.source);
83+
}
84+
7185
this.initialState = {
7286
counter: 0,
7387
};
@@ -81,14 +95,26 @@ export class StartWorkCommand extends QuickCommand<State> {
8195
const context: Context = {
8296
result: { items: [] },
8397
title: this.title,
98+
telemetryContext: this.telemetryContext,
8499
connectedIntegrations: await this.getConnectedIntegrations(),
85100
};
86101

102+
const opened = false;
87103
while (this.canStepsContinue(state)) {
88104
context.title = this.title;
89105

90106
const hasConnectedIntegrations = [...context.connectedIntegrations.values()].some(c => c);
91107
if (!hasConnectedIntegrations) {
108+
if (this.container.telemetry.enabled) {
109+
this.container.telemetry.sendEvent(
110+
opened ? 'startWork/steps/connect' : 'startWork/opened',
111+
{
112+
...context.telemetryContext!,
113+
connected: false,
114+
},
115+
this.source,
116+
);
117+
}
92118
const isUsingCloudIntegrations = configuration.get('cloudIntegrations.enabled', undefined, false);
93119
const result = isUsingCloudIntegrations
94120
? yield* this.confirmCloudIntegrationsConnectStep(state, context)

0 commit comments

Comments
 (0)