diff --git a/src/editors/mongoDBDocumentService.ts b/src/editors/mongoDBDocumentService.ts index c1586e17f..90a5e5a0a 100644 --- a/src/editors/mongoDBDocumentService.ts +++ b/src/editors/mongoDBDocumentService.ts @@ -3,12 +3,13 @@ import type { Document } from 'bson'; import type ConnectionController from '../connectionController'; import { createLogger } from '../logging'; -import { DocumentSource } from '../documentSource'; +import type { DocumentSource } from '../documentSource'; import type { EditDocumentInfo } from '../types/editDocumentInfoType'; import formatError from '../utils/formatError'; import type { StatusView } from '../views'; import type { TelemetryService } from '../telemetry'; import { DocumentUpdatedTelemetryEvent } from '../telemetry'; +import { getDocumentViewAndEditFormat } from './types'; const log = createLogger('document controller'); @@ -48,11 +49,15 @@ export default class MongoDBDocumentService { throw new Error(errorMessage); } - _saveDocumentFailed(message: string): void { + _saveDocumentFailed(message: string, source: DocumentSource): void { const errorMessage = `Unable to save document: ${message}`; this._telemetryService.track( - new DocumentUpdatedTelemetryEvent(DocumentSource.treeview, false), + new DocumentUpdatedTelemetryEvent( + source, + false, + getDocumentViewAndEditFormat(), + ), ); throw new Error(errorMessage); @@ -76,6 +81,7 @@ export default class MongoDBDocumentService { if (activeConnectionId !== connectionId) { return this._saveDocumentFailed( `no longer connected to '${connectionName}'`, + source, ); } @@ -84,6 +90,7 @@ export default class MongoDBDocumentService { if (dataService === null) { return this._saveDocumentFailed( `no longer connected to '${connectionName}'`, + source, ); } @@ -100,10 +107,14 @@ export default class MongoDBDocumentService { }, ); this._telemetryService.track( - new DocumentUpdatedTelemetryEvent(source, true), + new DocumentUpdatedTelemetryEvent( + source, + true, + getDocumentViewAndEditFormat(), + ), ); } catch (error) { - return this._saveDocumentFailed(formatError(error).message); + return this._saveDocumentFailed(formatError(error).message, source); } finally { this._statusView.hideMessage(); } diff --git a/src/mdbExtensionController.ts b/src/mdbExtensionController.ts index f5a0b39bb..7fa38caa1 100644 --- a/src/mdbExtensionController.ts +++ b/src/mdbExtensionController.ts @@ -552,7 +552,7 @@ export default class MDBExtensionController implements vscode.Disposable { ExtensionCommand.mdbOpenMongodbDocumentFromCodeLens, (data: EditDocumentInfo) => { this._telemetryService.track( - new DocumentEditedTelemetryEvent(data.source), + new DocumentEditedTelemetryEvent(data.source, data.format), ); return this._editorsController.openMongoDBDocument(data); diff --git a/src/telemetry/telemetryEvents.ts b/src/telemetry/telemetryEvents.ts index 62d9517fb..6ae55cbd9 100644 --- a/src/telemetry/telemetryEvents.ts +++ b/src/telemetry/telemetryEvents.ts @@ -1,6 +1,7 @@ import type { ExtensionCommand } from '../commands'; import type { DocumentSourceDetails } from '../documentSource'; import { DocumentSource } from '../documentSource'; +import type { DocumentViewAndEditFormat } from '../editors/types'; import type { ExportToPlaygroundError, ParticipantErrorType, @@ -220,10 +221,17 @@ export class DocumentUpdatedTelemetryEvent implements TelemetryEventBase { /** Whether the operation was successful */ success: boolean; + + /** Whether the user edited the document in shell format or ejson */ + view_format: DocumentViewAndEditFormat; }; - constructor(source: DocumentSource, success: boolean) { - this.properties = { source, success }; + constructor( + source: DocumentSource, + success: boolean, + view_format: DocumentViewAndEditFormat, + ) { + this.properties = { source, success, view_format }; } } @@ -233,10 +241,13 @@ export class DocumentEditedTelemetryEvent implements TelemetryEventBase { properties: { /** The source of the document - e.g. codelens, treeview, etc. */ source: DocumentSource; + + /** Whether the user opened the document in shell format or ejson */ + view_format: DocumentViewAndEditFormat; }; - constructor(source: DocumentSource) { - this.properties = { source }; + constructor(source: DocumentSource, view_format: DocumentViewAndEditFormat) { + this.properties = { source, view_format }; } } @@ -685,10 +696,17 @@ export class DataBrowserOpenedTelemetryEvent implements TelemetryEventBase { /** Whether the user is browsing a collection or viewing playground query results */ source: DataBrowserSource; + + /** Whether the user is viewing the documents in shell format or ejson */ + view_format: DocumentViewAndEditFormat; }; - constructor(collectionType: string, source: DataBrowserSource) { - this.properties = { collection_type: collectionType, source }; + constructor( + collectionType: string, + source: DataBrowserSource, + view_format: DocumentViewAndEditFormat, + ) { + this.properties = { collection_type: collectionType, source, view_format }; } } @@ -724,10 +742,16 @@ export class DataBrowserDocumentEditedTelemetryEvent implements TelemetryEventBa properties: { /** Whether the user is browsing a collection or viewing playground query results */ source: DataBrowserSource; + + /** Whether the user opened the document in shell format or ejson */ + view_format: DocumentViewAndEditFormat; }; - constructor(source: DataBrowserSource) { - this.properties = { source }; + constructor( + source: DataBrowserSource, + view_format: DocumentViewAndEditFormat, + ) { + this.properties = { source, view_format }; } } diff --git a/src/test/suite/telemetry/telemetryService.test.ts b/src/test/suite/telemetry/telemetryService.test.ts index 97b29a424..a44ff7490 100644 --- a/src/test/suite/telemetry/telemetryService.test.ts +++ b/src/test/suite/telemetry/telemetryService.test.ts @@ -25,6 +25,7 @@ import { } from '../../../telemetry'; import type { SegmentProperties } from '../../../telemetry/telemetryService'; import { ConnectionType } from '../../../connectionController'; +import { getDocumentViewAndEditFormat } from '../../../editors/types'; // eslint-disable-next-line @typescript-eslint/no-require-imports const { version } = require('../../../../package.json'); @@ -220,7 +221,11 @@ suite('Telemetry Controller Test Suite', function () { test('track document saved form a tree-view event', function () { const source = DocumentSource.treeview; testTelemetryService.track( - new DocumentUpdatedTelemetryEvent(source, true), + new DocumentUpdatedTelemetryEvent( + source, + true, + getDocumentViewAndEditFormat(), + ), ); sandbox.assert.calledWith( fakeSegmentAnalyticsTrack, @@ -230,6 +235,7 @@ suite('Telemetry Controller Test Suite', function () { properties: { source: 'treeview', success: true, + view_format: getDocumentViewAndEditFormat(), ...commonProperties, }, }), @@ -238,13 +244,22 @@ suite('Telemetry Controller Test Suite', function () { test('track document opened form playground results', function () { const source = DocumentSource.playground; - testTelemetryService.track(new DocumentEditedTelemetryEvent(source)); + testTelemetryService.track( + new DocumentEditedTelemetryEvent( + source, + getDocumentViewAndEditFormat(), + ), + ); sandbox.assert.calledWith( fakeSegmentAnalyticsTrack, sinon.match({ ...telemetryIdentity, event: 'Document Edited', - properties: { source: 'playground', extension_version: version }, + properties: { + source: 'playground', + view_format: getDocumentViewAndEditFormat(), + extension_version: version, + }, }), ); }); diff --git a/src/test/suite/views/dataBrowsingController.test.ts b/src/test/suite/views/dataBrowsingController.test.ts index 9a66b6ee9..128d1c7c3 100644 --- a/src/test/suite/views/dataBrowsingController.test.ts +++ b/src/test/suite/views/dataBrowsingController.test.ts @@ -1040,6 +1040,9 @@ suite('DataBrowsingController Test Suite', function () { expect(trackStub.firstCall.args[0].properties.source).to.equal( 'collection', ); + expect(trackStub.firstCall.args[0].properties.view_format).to.equal( + 'shell', + ); }); test('handleEditDocument does not track telemetry when command returns false', async function () { diff --git a/src/views/dataBrowsingController.ts b/src/views/dataBrowsingController.ts index 77cefc7d1..cc81e827f 100644 --- a/src/views/dataBrowsingController.ts +++ b/src/views/dataBrowsingController.ts @@ -551,19 +551,20 @@ export default class DataBrowsingController { documentId: any, ): Promise => { try { + const documentFormat = getDocumentViewAndEditFormat(); const result = await vscode.commands.executeCommand( ExtensionCommand.mdbOpenMongodbDocumentFromDataBrowser, { documentId, namespace: `${options.databaseName}.${options.collectionName}`, - format: getDocumentViewAndEditFormat(), + format: documentFormat, connectionId: this._connectionController.getActiveConnectionId(), }, ); if (result) { const source = options.query ? 'query-results' : 'collection'; this._telemetryService.track( - new DataBrowserDocumentEditedTelemetryEvent(source), + new DataBrowserDocumentEditedTelemetryEvent(source, documentFormat), ); } } catch (error) { @@ -1019,7 +1020,11 @@ export default class DataBrowsingController { ); const source = options.query ? 'query-results' : 'collection'; this._telemetryService.track( - new DataBrowserOpenedTelemetryEvent(options.collectionType, source), + new DataBrowserOpenedTelemetryEvent( + options.collectionType, + source, + getDocumentViewAndEditFormat(), + ), ); const extensionPath = context.extensionPath;