diff --git a/packages/amazonq/src/inlineChat/controller/inlineChatController.ts b/packages/amazonq/src/inlineChat/controller/inlineChatController.ts index ce0df6a0878..154531eaa25 100644 --- a/packages/amazonq/src/inlineChat/controller/inlineChatController.ts +++ b/packages/amazonq/src/inlineChat/controller/inlineChatController.ts @@ -13,6 +13,7 @@ import { computeDecorations } from '../decorations/computeDecorations' import { CodelensProvider } from '../codeLenses/codeLenseProvider' import { PromptMessage, ReferenceLogController } from 'aws-core-vscode/codewhispererChat' import { CodeWhispererSettings } from 'aws-core-vscode/codewhisperer' +import { QCodeGenTracker } from 'aws-core-vscode/codewhisperer' import { codicon, getIcon, @@ -68,6 +69,7 @@ export class InlineChatController { }, this.task ) + QCodeGenTracker.instance.onInlineChatAcceptance() } const deletions = task.diff.filter((diff) => diff.type === 'deletion') await editor.edit( diff --git a/packages/core/src/codewhisperer/index.ts b/packages/core/src/codewhisperer/index.ts index 54a1c508322..76e19a168a7 100644 --- a/packages/core/src/codewhisperer/index.ts +++ b/packages/core/src/codewhisperer/index.ts @@ -101,3 +101,4 @@ export * as CodeWhispererConstants from '../codewhisperer/models/constants' export { getSelectedCustomization } from './util/customizationUtil' export { Container } from './service/serviceContainer' export * from './util/gitUtil' +export { QCodeGenTracker } from './tracker/qCodeGenTracker' diff --git a/packages/core/src/codewhisperer/tracker/qCodeGenTracker.ts b/packages/core/src/codewhisperer/tracker/qCodeGenTracker.ts index c223c5d6c50..37e60a7d5ea 100644 --- a/packages/core/src/codewhisperer/tracker/qCodeGenTracker.ts +++ b/packages/core/src/codewhisperer/tracker/qCodeGenTracker.ts @@ -22,7 +22,7 @@ export class QCodeGenTracker { private _totalNewCodeCharacterCount: number private _totalNewCodeLineCount: number private _timer?: NodeJS.Timer - private _serviceInvocationCount: number + private _qUsageCount: number static #instance: QCodeGenTracker static copySnippetThreshold = 50 @@ -30,17 +30,13 @@ export class QCodeGenTracker { private constructor() { this._totalNewCodeLineCount = 0 this._totalNewCodeCharacterCount = 0 - this._serviceInvocationCount = 0 + this._qUsageCount = 0 } public static get instance() { return (this.#instance ??= new this()) } - public get serviceInvocationCount(): number { - return this._serviceInvocationCount - } - public isActive(): boolean { return TelemetryHelper.instance.isTelemetryEnabled() && AuthUtil.instance.isConnected() } @@ -48,7 +44,7 @@ export class QCodeGenTracker { // this should be invoked whenever there is a successful Q feature invocation // for all Q features public onQFeatureInvoked() { - this._serviceInvocationCount += 1 + this._qUsageCount += 1 } public emitCodeContribution() { @@ -98,7 +94,7 @@ export class QCodeGenTracker { const delay: number = CodeWhispererConstants.defaultCheckPeriodMillis const diffTime: number = startTime + delay if (diffTime <= currentTime) { - if (this._serviceInvocationCount <= 0) { + if (this._qUsageCount <= 0) { getLogger().debug(`Skip emiting code contribution metric. There is no active Amazon Q usage. `) return } @@ -120,7 +116,7 @@ export class QCodeGenTracker { private resetTracker() { this._totalNewCodeLineCount = 0 this._totalNewCodeCharacterCount = 0 - this._serviceInvocationCount = 0 + this._qUsageCount = 0 } private closeTimer() { @@ -171,20 +167,29 @@ export class QCodeGenTracker { } // add Q chat insert to cursor code to total code written - public onQChatInsertion() {} + public onQChatInsertion(acceptedCharacterCount?: number, acceptedLineCount?: number) { + if (acceptedCharacterCount && acceptedLineCount) { + // if the chat inserted code is less than 50 characters, it will be auto captured by onTextDocumentChange + if (acceptedCharacterCount <= QCodeGenTracker.copySnippetThreshold) { + return + } + this._totalNewCodeCharacterCount += acceptedCharacterCount + this._totalNewCodeLineCount += acceptedLineCount + } + } // add Q inline chat acceptance to total code written - public onInlineChat() {} + public onInlineChatAcceptance() {} - // add Q inline chat acceptance to total code written + // TODO: add Q inline chat acceptance to total code written public onTransformAcceptance() {} - // add Q feature dev acceptance to total code written + // TODO: add Q feature dev acceptance to total code written public onFeatureDevAcceptance() {} - // add Q UTG acceptance to total code written + // TODO: add Q UTG acceptance to total code written public onUtgAcceptance() {} - // add Q UTG acceptance to total code written + // TODO: add Q UTG acceptance to total code written public onDocAcceptance() {} } diff --git a/packages/core/src/codewhispererChat/controllers/chat/telemetryHelper.ts b/packages/core/src/codewhispererChat/controllers/chat/telemetryHelper.ts index feaeec75969..f460a38a7de 100644 --- a/packages/core/src/codewhispererChat/controllers/chat/telemetryHelper.ts +++ b/packages/core/src/codewhispererChat/controllers/chat/telemetryHelper.ts @@ -38,6 +38,7 @@ import { supportedLanguagesList } from '../chat/chatRequest/converter' import { AuthUtil } from '../../../codewhisperer/util/authUtil' import { getSelectedCustomization } from '../../../codewhisperer/util/customizationUtil' import { undefinedIfEmpty } from '../../../shared' +import { QCodeGenTracker } from '../../../codewhisperer/tracker/qCodeGenTracker' export function logSendTelemetryEventFailure(error: any) { let requestId: string | undefined @@ -321,7 +322,10 @@ export class CWCTelemetryHelper { return } telemetry.amazonq_interactWithMessage.emit(event) - + QCodeGenTracker.instance.onQChatInsertion( + event.cwsprChatAcceptedCharactersLength, + event.cwsprChatAcceptedNumberOfLines + ) codeWhispererClient .sendTelemetryEvent({ telemetryEvent: {