mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Add query history telemetry (#20722)
* Add query history telemetry * Update property name * Only send on success * Update name
This commit is contained in:
@@ -9,6 +9,7 @@ import { DOUBLE_CLICK_ACTION_CONFIG_SECTION, ITEM_SELECTED_COMMAND_ID, QUERY_HIS
|
||||
import { QueryHistoryItem } from './queryHistoryItem';
|
||||
import { QueryHistoryProvider, setLoadingContext } from './queryHistoryProvider';
|
||||
import { promises as fs } from 'fs';
|
||||
import { TelemetryActions, TelemetryReporter, TelemetryViews } from './telemetry';
|
||||
|
||||
let lastSelectedItem: { item: QueryHistoryItem | undefined, time: number | undefined } = {
|
||||
item: undefined,
|
||||
@@ -26,6 +27,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
|
||||
await fs.mkdir(storageUri.fsPath);
|
||||
} catch (err) {
|
||||
if (err.code !== 'EEXIST') {
|
||||
TelemetryReporter.sendErrorEvent(TelemetryViews.QueryHistory, 'CreatingStorageFolder');
|
||||
console.error(`Error creating query history global storage folder ${context.globalStorageUri.fsPath}. ${err}`);
|
||||
}
|
||||
}
|
||||
@@ -44,6 +46,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
|
||||
const clickTime = new Date().getTime();
|
||||
if (lastSelectedItem.item === selectedItem && lastSelectedItem.time && (clickTime - lastSelectedItem.time) < DOUBLE_CLICK_TIMEOUT_MS) {
|
||||
const doubleClickAction = vscode.workspace.getConfiguration(QUERY_HISTORY_CONFIG_SECTION).get<string>(DOUBLE_CLICK_ACTION_CONFIG_SECTION);
|
||||
TelemetryReporter.sendActionEvent(TelemetryViews.QueryHistory, TelemetryActions.DoubleClick, doubleClickAction);
|
||||
switch (doubleClickAction) {
|
||||
case 'run':
|
||||
await runQuery(selectedItem);
|
||||
@@ -91,21 +94,37 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
|
||||
}
|
||||
|
||||
async function openQuery(item: QueryHistoryItem): Promise<void> {
|
||||
await azdata.queryeditor.openQueryDocument(
|
||||
{
|
||||
content: item.queryText
|
||||
}, item.connectionProfile?.providerId);
|
||||
try {
|
||||
await azdata.queryeditor.openQueryDocument(
|
||||
{
|
||||
content: item.queryText
|
||||
}, item.connectionProfile?.providerId);
|
||||
} catch (err) {
|
||||
TelemetryReporter.sendErrorEvent(TelemetryViews.QueryHistory, 'OpenQuery');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function runQuery(item: QueryHistoryItem): Promise<void> {
|
||||
const doc = await azdata.queryeditor.openQueryDocument(
|
||||
{
|
||||
content: item.queryText
|
||||
}, item.connectionProfile?.providerId);
|
||||
if (item.connectionProfile) {
|
||||
await doc.connect(item.connectionProfile);
|
||||
} else {
|
||||
await azdata.queryeditor.connect(doc.uri, '');
|
||||
let step = 'OpenDoc';
|
||||
try {
|
||||
const doc = await azdata.queryeditor.openQueryDocument(
|
||||
{
|
||||
content: item.queryText
|
||||
}, item.connectionProfile?.providerId);
|
||||
if (item.connectionProfile) {
|
||||
step = 'ConnectWithProfile';
|
||||
await doc.connect(item.connectionProfile);
|
||||
} else {
|
||||
step = 'ConnectWithoutProfile';
|
||||
await azdata.queryeditor.connect(doc.uri, '');
|
||||
}
|
||||
step = 'Run';
|
||||
azdata.queryeditor.runQuery(doc.uri);
|
||||
} catch (err) {
|
||||
TelemetryReporter.createErrorEvent(TelemetryViews.QueryHistory, 'RunQuery')
|
||||
.withAdditionalProperties({ step })
|
||||
.send();
|
||||
}
|
||||
azdata.queryeditor.runQuery(doc.uri);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user