Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/editors/mongoDBDocumentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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(),
Comment thread
Anemy marked this conversation as resolved.
),
);

throw new Error(errorMessage);
Expand All @@ -76,6 +81,7 @@ export default class MongoDBDocumentService {
if (activeConnectionId !== connectionId) {
return this._saveDocumentFailed(
`no longer connected to '${connectionName}'`,
source,
);
}

Expand All @@ -84,6 +90,7 @@ export default class MongoDBDocumentService {
if (dataService === null) {
return this._saveDocumentFailed(
`no longer connected to '${connectionName}'`,
source,
);
}

Expand All @@ -100,10 +107,14 @@ export default class MongoDBDocumentService {
},
);
this._telemetryService.track(
new DocumentUpdatedTelemetryEvent(source, true),
new DocumentUpdatedTelemetryEvent(
source,
true,
getDocumentViewAndEditFormat(),
),
Comment thread
Anemy marked this conversation as resolved.
);
} catch (error) {
return this._saveDocumentFailed(formatError(error).message);
return this._saveDocumentFailed(formatError(error).message, source);
} finally {
this._statusView.hideMessage();
}
Expand Down
2 changes: 1 addition & 1 deletion src/mdbExtensionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 32 additions & 8 deletions src/telemetry/telemetryEvents.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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;
};
Comment thread
Anemy marked this conversation as resolved.

constructor(source: DocumentSource, success: boolean) {
this.properties = { source, success };
constructor(
source: DocumentSource,
success: boolean,
view_format: DocumentViewAndEditFormat,
) {
this.properties = { source, success, view_format };
}
}

Expand All @@ -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 };
}
}

Expand Down Expand Up @@ -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;
};
Comment thread
Anemy marked this conversation as resolved.

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 };
}
}

Expand Down Expand Up @@ -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 };
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/connectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@
);
});

test.skip('should track SAVED_CONNECTIONS_LOADED event on load of saved connections', async function () {

Check warning on line 1420 in src/test/suite/connectionController.test.ts

View workflow job for this annotation

GitHub Actions / Build and Check

Unexpected skipped mocha test
testSandbox.replace(testStorageController, 'get', (key, storage) => {
if (
storage === StorageLocation.workspace ||
Expand Down Expand Up @@ -1580,7 +1580,7 @@
'mongodb+srv://user:s3cr3t@cluster0.example.com/admin',
});

const dialogMessage = showWarningMessageStub.firstCall.args[0] as string;
const dialogMessage = showWarningMessageStub.firstCall.args[0];
expect(dialogMessage).to.include('cluster0.example.com');
expect(dialogMessage).to.not.include('s3cr3t');
});
Expand Down
21 changes: 18 additions & 3 deletions src/test/suite/telemetry/telemetryService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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-var-requires
const { version } = require('../../../../package.json');
Expand Down Expand Up @@ -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,
Expand All @@ -230,6 +235,7 @@ suite('Telemetry Controller Test Suite', function () {
properties: {
source: 'treeview',
success: true,
view_format: getDocumentViewAndEditFormat(),
...commonProperties,
},
}),
Expand All @@ -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,
},
}),
);
});
Expand Down
3 changes: 3 additions & 0 deletions src/test/suite/views/dataBrowsingController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,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',
);
Comment thread
Anemy marked this conversation as resolved.
});

test('handleEditDocument does not track telemetry when command returns false', async function () {
Expand Down
11 changes: 8 additions & 3 deletions src/views/dataBrowsingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,19 +551,20 @@ export default class DataBrowsingController {
documentId: any,
): Promise<void> => {
try {
const documentFormat = getDocumentViewAndEditFormat();
const result = await vscode.commands.executeCommand<boolean>(
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) {
Expand Down Expand Up @@ -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;

Expand Down
Loading