Skip to content

Commit

Permalink
Added telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
amitjoshi committed Oct 17, 2023
1 parent 6ba0b1f commit df0149c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/common/copilot/PowerPagesCopilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 } });
};
Expand All @@ -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)})
);
}

Expand Down
1 change: 1 addition & 0 deletions src/common/copilot/telemetry/ITelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export interface IProDevCopilotTelemetryData {
geoName?: string,
aibEndpoint?: string,
orgUrl?: string,
tokenSize?: string
}
3 changes: 2 additions & 1 deletion src/common/copilot/telemetry/copilotTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/common/copilot/telemetry/telemetryConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit df0149c

Please sign in to comment.