add telemetry to undo/redo at cell level (#17804)

* add telemetry to undo/redo at cell level

*add sendTelemetryActionEvent that sends telemetry from notebook model
This commit is contained in:
Barbara Valdez
2021-12-03 16:21:52 -08:00
committed by GitHub
parent cde4e05320
commit 8a205965d2
8 changed files with 57 additions and 30 deletions

View File

@@ -61,7 +61,6 @@ export class AddCellAction extends Action {
constructor(
id: string, label: string, cssClass: string,
@INotebookService private _notebookService: INotebookService,
@IAdsTelemetryService private _telemetryService: IAdsTelemetryService,
) {
super(id, label, cssClass);
}
@@ -76,16 +75,15 @@ export class AddCellAction extends Action {
}
if (context?.model) {
context.model.addCell(this.cellType, index);
context.model.sendNotebookTelemetryActionEvent(TelemetryKeys.NbTelemetryAction.AddCell, { cell_type: this.cellType });
}
} else {
//Add Cell after current selected cell.
const editor = this._notebookService.findNotebookEditor(context);
const index = editor.cells?.findIndex(cell => cell.active) ?? 0;
editor.addCell(this.cellType, index);
editor.model.sendNotebookTelemetryActionEvent(TelemetryKeys.NbTelemetryAction.AddCell, { cell_type: this.cellType });
}
this._telemetryService.createActionEvent(TelemetryKeys.TelemetryView.Notebook, TelemetryKeys.NbTelemetryAction.AddCell)
.withAdditionalProperties({ cell_type: this.cellType })
.send();
}
}
@@ -369,19 +367,13 @@ export class RunAllCellsAction extends Action {
id: string, label: string, cssClass: string,
@INotificationService private notificationService: INotificationService,
@INotebookService private _notebookService: INotebookService,
@IAdsTelemetryService private _telemetryService: IAdsTelemetryService,
) {
super(id, label, cssClass);
}
public override async run(context: URI): Promise<void> {
try {
const editor = this._notebookService.findNotebookEditor(context);
const azdata_notebook_guid: string = editor.model.getMetaValue('azdata_notebook_guid');
this._telemetryService.createActionEvent(TelemetryKeys.TelemetryView.Notebook, TelemetryKeys.NbTelemetryAction.RunAll)
.withAdditionalProperties({ azdata_notebook_guid })
.send();
editor.model.sendNotebookTelemetryActionEvent(TelemetryKeys.NbTelemetryAction.RunAll);
await editor.runAllCells();
} catch (e) {
this.notificationService.error(getErrorMessage(e));

View File

@@ -29,6 +29,8 @@ import { MockQuickInputService } from 'sql/workbench/contrib/notebook/test/commo
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
import { Separator } from 'vs/base/common/actions';
import { INotebookView, INotebookViews } from 'sql/workbench/services/notebook/browser/notebookViews/notebookViews';
import * as TelemetryKeys from 'sql/platform/telemetry/common/telemetryKeys';
import { ITelemetryEventProperties } from 'sql/platform/telemetry/common/telemetry';
class TestClientSession extends ClientSessionStub {
private _errorState: boolean = false;
@@ -106,6 +108,9 @@ class TestNotebookModel extends NotebookModelStub {
public override getStandardKernelFromName(name: string): IStandardKernelWithProvider {
return this._standardKernelsMap.get(name);
}
public override sendNotebookTelemetryActionEvent(action: TelemetryKeys.TelemetryAction | TelemetryKeys.NbTelemetryAction, additionalProperties?: ITelemetryEventProperties): void {
}
}
suite('Notebook Actions', function (): void {
@@ -113,9 +118,11 @@ suite('Notebook Actions', function (): void {
let mockNotebookEditor: TypeMoq.Mock<INotebookEditor>;
let mockNotebookService: TypeMoq.Mock<INotebookService>;
const testUri = URI.parse('untitled');
let testNotebookModel = new TestNotebookModel();
suiteSetup(function (): void {
mockNotebookEditor = TypeMoq.Mock.ofType<INotebookEditor>(NotebookEditorStub);
mockNotebookEditor.setup(x => x.model).returns(() => testNotebookModel);
mockNotebookService = TypeMoq.Mock.ofType<INotebookService>(NotebookServiceStub);
mockNotebookService.setup(x => x.findNotebookEditor(TypeMoq.It.isAny())).returns(uri => mockNotebookEditor.object);
});
@@ -129,7 +136,7 @@ suite('Notebook Actions', function (): void {
let actualCellType: CellType;
let action = new AddCellAction('TestId', 'TestLabel', 'TestClass', mockNotebookService.object, new NullAdsTelemetryService());
let action = new AddCellAction('TestId', 'TestLabel', 'TestClass', mockNotebookService.object);
action.cellType = testCellType;
// Normal use case
@@ -196,7 +203,7 @@ suite('Notebook Actions', function (): void {
let mockNotification = TypeMoq.Mock.ofType<INotificationService>(TestNotificationService);
mockNotification.setup(n => n.notify(TypeMoq.It.isAny()));
let action = new RunAllCellsAction('TestId', 'TestLabel', 'TestClass', mockNotification.object, mockNotebookService.object, new NullAdsTelemetryService());
let action = new RunAllCellsAction('TestId', 'TestLabel', 'TestClass', mockNotification.object, mockNotebookService.object);
// Normal use case
mockNotebookEditor.setup(c => c.runAllCells()).returns(() => Promise.resolve(true));

View File

@@ -21,6 +21,8 @@ import { IEditorPane } from 'vs/workbench/common/editor';
import { INotebookShowOptions } from 'sql/workbench/api/common/sqlExtHost.protocol';
import { NotebookViewsExtension } from 'sql/workbench/services/notebook/browser/notebookViews/notebookViewsExtension';
import { INotebookView, INotebookViewCell, INotebookViewMetadata, INotebookViews } from 'sql/workbench/services/notebook/browser/notebookViews/notebookViews';
import * as TelemetryKeys from 'sql/platform/telemetry/common/telemetryKeys';
import { ITelemetryEventProperties } from 'sql/platform/telemetry/common/telemetry';
export class NotebookModelStub implements INotebookModel {
constructor(private _languageInfo?: nb.ILanguageInfo, private _cells?: ICellModel[], private _testContents?: nb.INotebookContents) {
@@ -158,6 +160,8 @@ export class NotebookModelStub implements INotebookModel {
requestConnection(): Promise<boolean> {
throw new Error('Method not implemented.');
}
sendNotebookTelemetryActionEvent(action: TelemetryKeys.TelemetryAction | TelemetryKeys.NbTelemetryAction, additionalProperties?: ITelemetryEventProperties): void {
}
}
export class NotebookFindModelStub implements INotebookFindModel {