Skip to content

Commit 82c608d

Browse files
sergeibbbchivorotkiv
authored andcommitted
Adds some telemetry to start work flow
(#3621, #3698)
1 parent 8786292 commit 82c608d

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

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

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

450469
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';
@@ -42,6 +44,7 @@ export type StartWorkResult = { items: StartWorkItem[] };
4244
interface Context {
4345
result: StartWorkResult;
4446
title: string;
47+
telemetryContext: StartWorkTelemetryContext | undefined;
4548
connectedIntegrations: Map<IntegrationId, boolean>;
4649
}
4750

@@ -56,6 +59,7 @@ export type StartWorkAction = 'start';
5659

5760
export interface StartWorkCommandArgs {
5861
readonly command: 'startWork';
62+
source?: Sources;
5963
}
6064

6165
function assertsStartWorkStepState(state: StepState<State>): asserts state is StartWorkStepState {
@@ -66,13 +70,23 @@ function assertsStartWorkStepState(state: StepState<State>): asserts state is St
6670
}
6771

6872
export const supportedStartWorkIntegrations = [HostingIntegrationId.GitHub];
73+
const instanceCounter = getScopedCounter();
6974

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

83+
this.source = { source: args?.source ?? 'commandPalette' };
84+
85+
if (this.container.telemetry.enabled) {
86+
this.telemetryContext = { instance: instanceCounter.next() };
87+
this.container.telemetry.sendEvent('startWork/open', { ...this.telemetryContext }, this.source);
88+
}
89+
7690
this.initialState = {
7791
counter: 0,
7892
};
@@ -86,14 +100,26 @@ export class StartWorkCommand extends QuickCommand<State> {
86100
const context: Context = {
87101
result: { items: [] },
88102
title: this.title,
103+
telemetryContext: this.telemetryContext,
89104
connectedIntegrations: await this.getConnectedIntegrations(),
90105
};
91106

107+
const opened = false;
92108
while (this.canStepsContinue(state)) {
93109
context.title = this.title;
94110

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

0 commit comments

Comments
 (0)