Skip to content
Merged
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
37 changes: 20 additions & 17 deletions src/connectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { createLogger } from './logging';
import formatError from './utils/formatError';
import type { StorageController } from './storage';
import type { StatusView } from './views';
import type TelemetryService from './telemetry/telemetryService';
import type { TelemetryService } from './telemetry';
import { openLink } from './utils/linkHelper';
import type {
ConnectionSource,
Expand All @@ -28,8 +28,8 @@ import type {
import { ConnectionStorage } from './storage/connectionStorage';
import LINKS from './utils/links';
import { isAtlasStream } from 'mongodb-build-info';
import { DocumentSource } from './documentSource';
import type { ConnectionTreeItem } from './explorer';
import { PresetConnectionEditedTelemetryEvent } from './telemetry';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJSON = require('../package.json');
Expand Down Expand Up @@ -129,18 +129,20 @@ export default class ConnectionController {
// have a setting on the system for storing credentials.
// When the setting is on this `connectionMergeInfos` would have the session
// credential information and merge it before connecting.
connectionMergeInfos: Record<string, RecursivePartial<LoadedConnection>> =
Object.create(null);
private _connectionMergeInfos: Record<
string,
RecursivePartial<LoadedConnection>
> = Object.create(null);

_activeDataService: DataService | null = null;
private _activeDataService: DataService | null = null;
_connectionStorage: ConnectionStorage;
_telemetryService: TelemetryService;

private readonly _serviceName = 'mdb.vscode.savedConnections';
private _currentConnectionId: null | string = null;

_connectionAttempt: null | ConnectionAttempt = null;
_connectionStringInputCancellationToken: null | vscode.CancellationTokenSource =
private _connectionStringInputCancellationToken: null | vscode.CancellationTokenSource =
null;
private _connectingConnectionId: null | string = null;
private _disconnecting = false;
Expand Down Expand Up @@ -169,10 +171,11 @@ export default class ConnectionController {
async openPresetConnectionsSettings(
originTreeItem: ConnectionTreeItem | undefined
): Promise<void> {
this._telemetryService.trackPresetConnectionEdited({
source: DocumentSource.DOCUMENT_SOURCE_TREEVIEW,
source_details: originTreeItem ? 'tree_item' : 'header',
});
this._telemetryService.track(
new PresetConnectionEditedTelemetryEvent(
originTreeItem ? 'tree_item' : 'header'
)
);
let source: ConnectionSource | undefined = originTreeItem?.source;
if (!source) {
const mdbConfiguration = vscode.workspace.getConfiguration('mdb');
Expand Down Expand Up @@ -227,7 +230,7 @@ export default class ConnectionController {

// TODO: re-enable with fewer 'Saved Connections Loaded' events
// https://jira.mongodb.org/browse/VSCODE-462
/* this._telemetryService.trackSavedConnectionsLoaded({
/* this._telemetryService.track(new SavedConnectionsLoadedTelemetryEvent({
saved_connections: globalAndWorkspaceConnections.length,
loaded_connections: loadedConnections.length,
).length,
Expand All @@ -236,7 +239,7 @@ export default class ConnectionController {
connection.secretStorageLocation ===
SecretStorageLocation.SecretStorage
).length,
}); */
})); */
}

async connectWithURI(): Promise<boolean> {
Expand Down Expand Up @@ -402,7 +405,7 @@ export default class ConnectionController {

const connectionInfo: LoadedConnection = merge(
cloneDeep(this._connections[connectionId]),
this.connectionMergeInfos[connectionId] ?? {}
this._connectionMergeInfos[connectionId] ?? {}
);

if (!connectionInfo.connectionOptions) {
Expand Down Expand Up @@ -557,8 +560,8 @@ export default class ConnectionController {
mergeConnectionInfo = {
connectionOptions: await dataService.getUpdatedSecrets(),
};
this.connectionMergeInfos[connectionInfo.id] = merge(
cloneDeep(this.connectionMergeInfos[connectionInfo.id]),
this._connectionMergeInfos[connectionInfo.id] = merge(
cloneDeep(this._connectionMergeInfos[connectionInfo.id]),
mergeConnectionInfo
);
}
Expand All @@ -585,8 +588,8 @@ export default class ConnectionController {
connectionOptions: await dataService.getUpdatedSecrets(),
};
if (!mergeConnectionInfo) return;
this.connectionMergeInfos[connectionInfo.id] = merge(
cloneDeep(this.connectionMergeInfos[connectionInfo.id]),
this._connectionMergeInfos[connectionInfo.id] = merge(
cloneDeep(this._connectionMergeInfos[connectionInfo.id]),
mergeConnectionInfo
);

Expand Down
2 changes: 2 additions & 0 deletions src/documentSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export enum DocumentSource {
DOCUMENT_SOURCE_COLLECTIONVIEW = 'collectionview',
DOCUMENT_SOURCE_CODELENS = 'codelens',
}

export type DocumentSourceDetails = 'database' | 'collection' | undefined;
2 changes: 1 addition & 1 deletion src/editors/editorsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type PlaygroundController from './playgroundController';
import type PlaygroundResultProvider from './playgroundResultProvider';
import { PLAYGROUND_RESULT_SCHEME } from './playgroundResultProvider';
import { StatusView } from '../views';
import type TelemetryService from '../telemetry/telemetryService';
import type { TelemetryService } from '../telemetry';
import type { QueryWithCopilotCodeLensProvider } from './queryWithCopilotCodeLensProvider';

const log = createLogger('editors controller');
Expand Down
15 changes: 10 additions & 5 deletions src/editors/mongoDBDocumentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { DocumentSource } from '../documentSource';
import type { EditDocumentInfo } from '../types/editDocumentInfoType';
import formatError from '../utils/formatError';
import type { StatusView } from '../views';
import type TelemetryService from '../telemetry/telemetryService';
import type { TelemetryService } from '../telemetry';
import { getEJSON } from '../utils/ejson';
import { DocumentUpdatedTelemetryEvent } from '../telemetry';

const log = createLogger('document controller');

Expand Down Expand Up @@ -50,9 +51,11 @@ export default class MongoDBDocumentService {
_saveDocumentFailed(message: string): void {
const errorMessage = `Unable to save document: ${message}`;

this._telemetryService.trackDocumentUpdated(
DocumentSource.DOCUMENT_SOURCE_TREEVIEW,
false
this._telemetryService.track(
new DocumentUpdatedTelemetryEvent(
DocumentSource.DOCUMENT_SOURCE_TREEVIEW,
false
)
);

throw new Error(errorMessage);
Expand Down Expand Up @@ -98,7 +101,9 @@ export default class MongoDBDocumentService {
returnDocument: 'after',
}
);
this._telemetryService.trackDocumentUpdated(source, true);
this._telemetryService.track(
new DocumentUpdatedTelemetryEvent(source, true)
);
} catch (error) {
return this._saveDocumentFailed(formatError(error).message);
} finally {
Expand Down
68 changes: 41 additions & 27 deletions src/editors/playgroundController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ import {
import playgroundSearchTemplate from '../templates/playgroundSearchTemplate';
import playgroundTemplate from '../templates/playgroundTemplate';
import type { StatusView } from '../views';
import type TelemetryService from '../telemetry/telemetryService';
import {
isPlayground,
getSelectedText,
getAllText,
getPlaygroundExtensionForTelemetry,
} from '../utils/playground';
import type { TelemetryService } from '../telemetry';
import { isPlayground, getSelectedText, getAllText } from '../utils/playground';
import type ExportToLanguageCodeLensProvider from './exportToLanguageCodeLensProvider';
import { playgroundFromDatabaseTreeItemTemplate } from '../templates/playgroundFromDatabaseTreeItemTemplate';
import { playgroundFromCollectionTreeItemTemplate } from '../templates/playgroundFromCollectionTreeItemTemplate';
import {
PlaygroundCreatedTelemetryEvent,
PlaygroundExecutedTelemetryEvent,
PlaygroundSavedTelemetryEvent,
} from '../telemetry';

const log = createLogger('playground controller');

Expand Down Expand Up @@ -135,17 +135,15 @@ export default class PlaygroundController {
if (isPlayground(document.uri)) {
// TODO: re-enable with fewer 'Playground Loaded' events
// https://jira.mongodb.org/browse/VSCODE-432
/* this._telemetryService.trackPlaygroundLoaded(
getPlaygroundExtensionForTelemetry(document.uri)
); */
// this._telemetryService.track(new PlaygroundLoadedTelemetryEvent(document.uri));
await vscode.languages.setTextDocumentLanguage(document, 'javascript');
}
});

vscode.workspace.onDidSaveTextDocument((document) => {
if (isPlayground(document.uri)) {
this._telemetryService.trackPlaygroundSaved(
getPlaygroundExtensionForTelemetry(document.uri)
this._telemetryService.track(
new PlaygroundSavedTelemetryEvent(document.uri)
);
}
});
Expand Down Expand Up @@ -231,7 +229,7 @@ export default class PlaygroundController {
.replace('CURRENT_DATABASE', databaseName)
.replace('CURRENT_COLLECTION', collectionName);

this._telemetryService.trackPlaygroundCreated('search');
this._telemetryService.track(new PlaygroundCreatedTelemetryEvent('search'));
return this._createPlaygroundFileWithContent(content);
}

Expand All @@ -246,9 +244,13 @@ export default class PlaygroundController {
content = content
.replace('NEW_DATABASE_NAME', element.databaseName)
.replace('Create a new database', 'The current database to use');
this._telemetryService.trackPlaygroundCreated('createCollection');
this._telemetryService.track(
new PlaygroundCreatedTelemetryEvent('createCollection')
);
} else {
this._telemetryService.trackPlaygroundCreated('createDatabase');
this._telemetryService.track(
new PlaygroundCreatedTelemetryEvent('createDatabase')
);
}

return this._createPlaygroundFileWithContent(content);
Expand All @@ -262,7 +264,7 @@ export default class PlaygroundController {
.replace('CURRENT_DATABASE', databaseName)
.replace('CURRENT_COLLECTION', collectionName);

this._telemetryService.trackPlaygroundCreated('index');
this._telemetryService.track(new PlaygroundCreatedTelemetryEvent('index'));
return this._createPlaygroundFileWithContent(content);
}

Expand All @@ -277,7 +279,7 @@ export default class PlaygroundController {
const content = useDefaultTemplate
? playgroundBasicTextTemplate.replace('PLAYGROUND_CONTENT', text)
: text;
this._telemetryService.trackPlaygroundCreated('agent');
this._telemetryService.track(new PlaygroundCreatedTelemetryEvent('agent'));
return this._createPlaygroundFileWithContent(content);
}

Expand All @@ -291,7 +293,9 @@ export default class PlaygroundController {
.replace('CURRENT_COLLECTION', collectionName)
.replace('DOCUMENT_CONTENTS', documentContents);

this._telemetryService.trackPlaygroundCreated('cloneDocument');
this._telemetryService.track(
new PlaygroundCreatedTelemetryEvent('cloneDocument')
);
return this._createPlaygroundFileWithContent(content);
}

Expand All @@ -303,7 +307,9 @@ export default class PlaygroundController {
.replace('CURRENT_DATABASE', databaseName)
.replace('CURRENT_COLLECTION', collectionName);

this._telemetryService.trackPlaygroundCreated('insertDocument');
this._telemetryService.track(
new PlaygroundCreatedTelemetryEvent('insertDocument')
);
return this._createPlaygroundFileWithContent(content);
}

Expand All @@ -314,7 +320,9 @@ export default class PlaygroundController {

element.cacheIsUpToDate = false;

this._telemetryService.trackPlaygroundCreated('createStreamProcessor');
this._telemetryService.track(
new PlaygroundCreatedTelemetryEvent('createStreamProcessor')
);

return this._createPlaygroundFileWithContent(content);
}
Expand All @@ -325,13 +333,17 @@ export default class PlaygroundController {
let content = '';
if (treeItem instanceof DatabaseTreeItem) {
content = playgroundFromDatabaseTreeItemTemplate(treeItem.databaseName);
this._telemetryService.trackPlaygroundCreated('fromDatabaseTreeItem');
this._telemetryService.track(
new PlaygroundCreatedTelemetryEvent('fromDatabaseTreeItem')
);
} else if (treeItem instanceof CollectionTreeItem) {
content = playgroundFromCollectionTreeItemTemplate(
treeItem.databaseName,
treeItem.collectionName
);
this._telemetryService.trackPlaygroundCreated('fromCollectionTreeItem');
this._telemetryService.track(
new PlaygroundCreatedTelemetryEvent('fromCollectionTreeItem')
);
}

return this._createPlaygroundFileWithContent(content);
Expand All @@ -350,7 +362,7 @@ export default class PlaygroundController {
content = template;
}

this._telemetryService.trackPlaygroundCreated('crud');
this._telemetryService.track(new PlaygroundCreatedTelemetryEvent('crud'));
return this._createPlaygroundFileWithContent(content);
}

Expand Down Expand Up @@ -391,10 +403,12 @@ export default class PlaygroundController {
}

this._statusView.hideMessage();
this._telemetryService.trackPlaygroundCodeExecuted(
result,
this._isPartialRun,
result ? false : true
this._telemetryService.track(
new PlaygroundExecutedTelemetryEvent(
result,
this._isPartialRun,
result ? false : true
)
);

return result;
Expand Down
1 change: 1 addition & 0 deletions src/editors/queryWithCopilotCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class QueryWithCopilotCodeLensProvider
isNewChat: true,
telemetry: {
source: DocumentSource.DOCUMENT_SOURCE_CODELENS,
source_details: undefined,
},
};

Expand Down
5 changes: 4 additions & 1 deletion src/explorer/helpTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getImagesPath } from '../extensionConstants';
import type { TelemetryService } from '../telemetry';
import { openLink } from '../utils/linkHelper';
import LINKS from '../utils/links';
import { LinkClickedTelemetryEvent } from '../telemetry';

const HELP_LINK_CONTEXT_VALUE = 'HELP_LINK';

Expand Down Expand Up @@ -144,7 +145,9 @@ export default class HelpTree
telemetryService: TelemetryService
): Promise<void> {
if (helpItem.contextValue === HELP_LINK_CONTEXT_VALUE) {
telemetryService.trackLinkClicked('helpPanel', helpItem.linkId);
telemetryService.track(
new LinkClickedTelemetryEvent('helpPanel', helpItem.linkId)
);

if (helpItem.useRedirect) {
try {
Expand Down
Loading
Loading