From df0149c2f45544121f4d8131094484d258fd110a Mon Sep 17 00:00:00 2001 From: amitjoshi Date: Tue, 17 Oct 2023 10:13:15 +0530 Subject: [PATCH] Added telemetry --- src/common/copilot/PowerPagesCopilot.ts | 16 ++++++++++------ src/common/copilot/telemetry/ITelemetry.ts | 1 + src/common/copilot/telemetry/copilotTelemetry.ts | 3 ++- .../copilot/telemetry/telemetryConstants.ts | 2 ++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/common/copilot/PowerPagesCopilot.ts b/src/common/copilot/PowerPagesCopilot.ts index 15b3d527..a2e98d05 100644 --- a/src/common/copilot/PowerPagesCopilot.ts +++ b/src/common/copilot/PowerPagesCopilot.ts @@ -16,14 +16,14 @@ import { escapeDollarSign, getLastThreePartsOfFileName, getNonce, getSelectedCod import { CESUserFeedback } from "./user-feedback/CESSurvey"; import { GetAuthProfileWatchPattern } from "../../client/lib/AuthPanelView"; import { ActiveOrgOutput } from "../../client/pac/PacTypes"; -import { CopilotWalkthroughEvent, CopilotCopyCodeToClipboardEvent, CopilotInsertCodeToEditorEvent, CopilotLoadedEvent, CopilotOrgChangedEvent, CopilotUserFeedbackThumbsDownEvent, CopilotUserFeedbackThumbsUpEvent, CopilotUserPromptedEvent, CopilotCodeLineCountEvent, CopilotClearChatEvent, CopilotNotAvailable } from "./telemetry/telemetryConstants"; +import { CopilotWalkthroughEvent, CopilotCopyCodeToClipboardEvent, CopilotInsertCodeToEditorEvent, CopilotLoadedEvent, CopilotOrgChangedEvent, CopilotUserFeedbackThumbsDownEvent, CopilotUserFeedbackThumbsUpEvent, CopilotUserPromptedEvent, CopilotCodeLineCountEvent, CopilotClearChatEvent, CopilotNotAvailable, CopilotExplainCode, CopilotExplainCodeSize } from "./telemetry/telemetryConstants"; import { sendTelemetryEvent } from "./telemetry/copilotTelemetry"; import { INTELLIGENCE_SCOPE_DEFAULT, PROVIDER_ID } from "../../web/client/common/constants"; import { getIntelligenceEndpoint } from "../ArtemisService"; import TelemetryReporter from "@vscode/extension-telemetry"; import { getEntityColumns, getEntityName } from "./dataverseMetadata"; import { COPILOT_STRINGS } from "./assets/copilotStrings"; -import { isWithinTokenLimit } from "gpt-tokenizer"; +import { isWithinTokenLimit, encode } from "gpt-tokenizer"; let intelligenceApiToken: string; let userID: string; // Populated from PAC or intelligence API @@ -84,9 +84,13 @@ export class PowerPagesCopilot implements vscode.WebviewViewProvider { return; } const withinTokenLimit = isWithinTokenLimit(selectedCode, 1000); - if(withinTokenLimit === false && commandType === EXPLAIN_CODE) { - vscode.window.showInformationMessage(vscode.l10n.t('Selection is too long! Please select a smaller portion of code.')); - return; + if(commandType === EXPLAIN_CODE) { + const tokenSize = encode(selectedCode).length; + sendTelemetryEvent(this.telemetry, { eventName: CopilotExplainCodeSize, copilotSessionId: sessionID, orgId: orgID, codeLineCount: String(selectedCodeLineRange.end - selectedCodeLineRange.start), tokenSize: String(tokenSize) }); + if(withinTokenLimit === false) { + vscode.window.showInformationMessage(vscode.l10n.t('Selection is too long! Please select a smaller portion of code.')); + return; + } } this.sendMessageToWebview({ type: commandType, value: { start: selectedCodeLineRange.start, end: selectedCodeLineRange.end, selectedCode: selectedCode, tokenSize: withinTokenLimit } }); }; @@ -96,7 +100,7 @@ export class PowerPagesCopilot implements vscode.WebviewViewProvider { ); this._disposables.push( - vscode.commands.registerCommand("powerpages.copilot.explain", () => { this.show(); handleSelectionChange(EXPLAIN_CODE)}) + vscode.commands.registerCommand("powerpages.copilot.explain", () => {sendTelemetryEvent(this.telemetry, { eventName: CopilotExplainCode, copilotSessionId: sessionID, orgId: orgID }); this.show(); handleSelectionChange(EXPLAIN_CODE)}) ); } diff --git a/src/common/copilot/telemetry/ITelemetry.ts b/src/common/copilot/telemetry/ITelemetry.ts index b8cb287a..506c5913 100644 --- a/src/common/copilot/telemetry/ITelemetry.ts +++ b/src/common/copilot/telemetry/ITelemetry.ts @@ -18,4 +18,5 @@ export interface IProDevCopilotTelemetryData { geoName?: string, aibEndpoint?: string, orgUrl?: string, + tokenSize?: string } diff --git a/src/common/copilot/telemetry/copilotTelemetry.ts b/src/common/copilot/telemetry/copilotTelemetry.ts index 7fc729b0..af5e328e 100644 --- a/src/common/copilot/telemetry/copilotTelemetry.ts +++ b/src/common/copilot/telemetry/copilotTelemetry.ts @@ -25,7 +25,8 @@ export function sendTelemetryEvent(telemetry: ITelemetry, telemetryData: IProDev telemetryDataProperties.FeedbackId = telemetryData.FeedbackId ? telemetryData.FeedbackId : ''; telemetryDataProperties.dataverseEntity = telemetryData.dataverseEntity ? telemetryData.dataverseEntity : ''; telemetryDataProperties.responseStatus = telemetryData.responseStatus ? telemetryData.responseStatus : ''; - + telemetryDataProperties.tokenSize = telemetryData.tokenSize ? telemetryData.tokenSize : ''; + if (telemetryData.error) { telemetryDataProperties.eventName = telemetryData.eventName; telemetry.sendTelemetryException(telemetryData.error, telemetryDataProperties, telemetryDataMeasurements); diff --git a/src/common/copilot/telemetry/telemetryConstants.ts b/src/common/copilot/telemetry/telemetryConstants.ts index 676646a0..7295dac8 100644 --- a/src/common/copilot/telemetry/telemetryConstants.ts +++ b/src/common/copilot/telemetry/telemetryConstants.ts @@ -33,3 +33,5 @@ export const CopilotNotificationShown = 'CopilotNotificationShown'; export const CopilotNotificationDoNotShowChecked = 'CopilotNotificationDoNotShowChecked'; export const CopilotNotificationDoNotShowUnchecked = 'CopilotNotificationDoNotShowUnchecked'; export const CopilotNotAvailable = 'CopilotNotAvailable'; +export const CopilotExplainCode = 'CopilotExplainCode'; +export const CopilotExplainCodeSize = 'CopilotExplainCodeSize';