Skip to content

Commit f881b13

Browse files
feat: add playground created telemetry event VSCODE-379 (#508)
* feat: add playground created telemetry event VSCODE-379 * feat: add playground file type to playground loaded and saved telemetry
1 parent 271a312 commit f881b13

File tree

7 files changed

+280
-55
lines changed

7 files changed

+280
-55
lines changed

src/editors/playgroundController.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ import playgroundSearchTemplate from '../templates/playgroundSearchTemplate';
4040
import playgroundTemplate from '../templates/playgroundTemplate';
4141
import { StatusView } from '../views';
4242
import TelemetryService from '../telemetry/telemetryService';
43-
import { isPlayground } from '../utils/playground';
43+
import {
44+
isPlayground,
45+
getPlaygroundExtensionForTelemetry,
46+
} from '../utils/playground';
4447

4548
const log = createLogger('playground controller');
4649

@@ -188,14 +191,18 @@ export default class PlaygroundController {
188191

189192
vscode.workspace.onDidOpenTextDocument(async (document) => {
190193
if (isPlayground(document.uri)) {
191-
this._telemetryService.trackPlaygroundLoaded();
194+
this._telemetryService.trackPlaygroundLoaded(
195+
getPlaygroundExtensionForTelemetry(document.uri)
196+
);
192197
await vscode.languages.setTextDocumentLanguage(document, 'javascript');
193198
}
194199
});
195200

196201
vscode.workspace.onDidSaveTextDocument((document) => {
197202
if (isPlayground(document.uri)) {
198-
this._telemetryService.trackPlaygroundSaved();
203+
this._telemetryService.trackPlaygroundSaved(
204+
getPlaygroundExtensionForTelemetry(document.uri)
205+
);
199206
}
200207
});
201208

@@ -327,6 +334,7 @@ export default class PlaygroundController {
327334
.replace('CURRENT_DATABASE', databaseName)
328335
.replace('CURRENT_COLLECTION', collectionName);
329336

337+
this._telemetryService.trackPlaygroundCreated('search');
330338
return this._createPlaygroundFileWithContent(content);
331339
}
332340

@@ -341,6 +349,9 @@ export default class PlaygroundController {
341349
content = content
342350
.replace('NEW_DATABASE_NAME', element.databaseName)
343351
.replace('Create a new database', 'The current database to use');
352+
this._telemetryService.trackPlaygroundCreated('createCollection');
353+
} else {
354+
this._telemetryService.trackPlaygroundCreated('createDatabase');
344355
}
345356

346357
return this._createPlaygroundFileWithContent(content);
@@ -354,6 +365,7 @@ export default class PlaygroundController {
354365
.replace('CURRENT_DATABASE', databaseName)
355366
.replace('CURRENT_COLLECTION', collectionName);
356367

368+
this._telemetryService.trackPlaygroundCreated('index');
357369
return this._createPlaygroundFileWithContent(content);
358370
}
359371

@@ -367,6 +379,7 @@ export default class PlaygroundController {
367379
.replace('CURRENT_COLLECTION', collectionName)
368380
.replace('DOCUMENT_CONTENTS', documentContents);
369381

382+
this._telemetryService.trackPlaygroundCreated('cloneDocument');
370383
return this._createPlaygroundFileWithContent(content);
371384
}
372385

@@ -378,6 +391,7 @@ export default class PlaygroundController {
378391
.replace('CURRENT_DATABASE', databaseName)
379392
.replace('CURRENT_COLLECTION', collectionName);
380393

394+
this._telemetryService.trackPlaygroundCreated('insertDocument');
381395
return this._createPlaygroundFileWithContent(content);
382396
}
383397

@@ -386,6 +400,8 @@ export default class PlaygroundController {
386400
.getConfiguration('mdb')
387401
.get('useDefaultTemplateForPlayground');
388402
const content = useDefaultTemplate ? playgroundTemplate : '';
403+
404+
this._telemetryService.trackPlaygroundCreated('crud');
389405
return this._createPlaygroundFileWithContent(content);
390406
}
391407

src/telemetry/telemetryService.ts

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export type SegmentProperties = {
3232

3333
type LinkClickedTelemetryEventProperties = {
3434
screen: string;
35-
link_id: string; // eslint-disable-line camelcase
35+
link_id: string;
3636
};
3737

3838
type ExtensionCommandRunTelemetryEventProperties = {
@@ -48,15 +48,25 @@ type DocumentEditedTelemetryEventProperties = {
4848
source: DocumentSource;
4949
};
5050

51-
/* eslint-disable camelcase */
5251
type QueryExportedTelemetryEventProperties = {
5352
language: string;
5453
num_stages?: number;
5554
with_import_statements: boolean;
5655
with_builders: boolean;
5756
with_driver_syntax: boolean;
5857
};
59-
/* eslint-enable camelcase */
58+
59+
type PlaygroundCreatedTelemetryEventProperties = {
60+
playground_type: string;
61+
};
62+
63+
type PlaygroundSavedTelemetryEventProperties = {
64+
file_type?: string;
65+
};
66+
67+
type PlaygroundLoadedTelemetryEventProperties = {
68+
file_type?: string;
69+
};
6070

6171
export type TelemetryEventProperties =
6272
| PlaygroundTelemetryEventProperties
@@ -65,7 +75,10 @@ export type TelemetryEventProperties =
6575
| NewConnectionTelemetryEventProperties
6676
| DocumentUpdatedTelemetryEventProperties
6777
| DocumentEditedTelemetryEventProperties
68-
| QueryExportedTelemetryEventProperties;
78+
| QueryExportedTelemetryEventProperties
79+
| PlaygroundCreatedTelemetryEventProperties
80+
| PlaygroundSavedTelemetryEventProperties
81+
| PlaygroundLoadedTelemetryEventProperties;
6982

7083
export enum TelemetryEventTypes {
7184
PLAYGROUND_CODE_EXECUTED = 'Playground Code Executed',
@@ -78,6 +91,7 @@ export enum TelemetryEventTypes {
7891
DOCUMENT_EDITED = 'Document Edited',
7992
QUERY_EXPORTED = 'Query Exported',
8093
AGGREGATION_EXPORTED = 'Aggregation Exported',
94+
PLAYGROUND_CREATED = 'Playground Created',
8195
}
8296

8397
/**
@@ -117,11 +131,11 @@ export default class TelemetryService {
117131
const constantsFile = fs.readFileSync(segmentKeyFileLocation, 'utf8');
118132
const constants = JSON.parse(constantsFile) as { segmentKey: string };
119133

120-
log.info('SegmentKey received', { type: typeof constants.segmentKey });
134+
log.info('SegmentKey was found', { type: typeof constants.segmentKey });
121135

122136
return constants.segmentKey;
123137
} catch (error) {
124-
log.error('Reading SegmentKey failed', error);
138+
log.error('SegmentKey was not found', error);
125139
return;
126140
}
127141
}
@@ -183,7 +197,7 @@ export default class TelemetryService {
183197
if (error) {
184198
log.error('Failed to track telemetry', error);
185199
} else {
186-
log.info('Telemetry sent', error);
200+
log.info('Telemetry sent', segmentProperties);
187201
}
188202
});
189203
}
@@ -285,12 +299,16 @@ export default class TelemetryService {
285299
});
286300
}
287301

288-
trackPlaygroundLoaded(): void {
289-
this.track(TelemetryEventTypes.PLAYGROUND_LOADED);
302+
trackPlaygroundLoaded(fileType?: string): void {
303+
this.track(TelemetryEventTypes.PLAYGROUND_LOADED, {
304+
file_type: fileType,
305+
});
290306
}
291307

292-
trackPlaygroundSaved(): void {
293-
this.track(TelemetryEventTypes.PLAYGROUND_SAVED);
308+
trackPlaygroundSaved(fileType?: string): void {
309+
this.track(TelemetryEventTypes.PLAYGROUND_SAVED, {
310+
file_type: fileType,
311+
});
294312
}
295313

296314
trackDocumentUpdated(source: DocumentSource, success: boolean): void {
@@ -312,4 +330,10 @@ export default class TelemetryService {
312330
): void {
313331
this.track(TelemetryEventTypes.AGGREGATION_EXPORTED, aggExportedProps);
314332
}
333+
334+
trackPlaygroundCreated(playgroundType: string): void {
335+
this.track(TelemetryEventTypes.PLAYGROUND_CREATED, {
336+
playground_type: playgroundType,
337+
});
338+
}
315339
}

src/test/fixture/testSaving.mongodb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
show dbs
1+
use('test');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* global use, db */
2+
3+
use('test');

src/test/suite/explorer/playgroundsExplorer.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ suite('Playgrounds Controller Test Suite', function () {
5050
try {
5151
const rootPath = path.resolve(__dirname, '../../../..');
5252
const children = await treeController.getPlaygrounds(rootPath);
53-
assert.strictEqual(Object.keys(children).length, 7);
53+
54+
// The number of playground files in the project repository.
55+
assert.strictEqual(Object.keys(children).length, 8);
5456
} catch (error) {
5557
assert(false, error as Error);
5658
}
@@ -69,7 +71,9 @@ suite('Playgrounds Controller Test Suite', function () {
6971
const rootPath = path.resolve(__dirname, '../../../..');
7072
const children = await treeController.getPlaygrounds(rootPath);
7173

72-
assert.strictEqual(Object.keys(children).length, 3);
74+
// The number of playground files in the project repository,
75+
// excluding the ./playgrounds directory.
76+
assert.strictEqual(Object.keys(children).length, 4);
7377
} catch (error) {
7478
assert(false, error as Error);
7579
}

0 commit comments

Comments
 (0)