Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
leigaol committed Dec 11, 2024
1 parent dd72f01 commit ad0e018
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -68,6 +69,7 @@ export class InlineChatController {
},
this.task
)
QCodeGenTracker.instance.onInlineChatAcceptance()
}
const deletions = task.diff.filter((diff) => diff.type === 'deletion')
await editor.edit(
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/codewhisperer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
35 changes: 20 additions & 15 deletions packages/core/src/codewhisperer/tracker/qCodeGenTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,29 @@ 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

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()
}

// 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() {
Expand Down Expand Up @@ -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
}
Expand All @@ -120,7 +116,7 @@ export class QCodeGenTracker {
private resetTracker() {
this._totalNewCodeLineCount = 0
this._totalNewCodeCharacterCount = 0
this._serviceInvocationCount = 0
this._qUsageCount = 0
}

private closeTimer() {
Expand Down Expand Up @@ -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() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -321,7 +322,10 @@ export class CWCTelemetryHelper {
return
}
telemetry.amazonq_interactWithMessage.emit(event)

QCodeGenTracker.instance.onQChatInsertion(
event.cwsprChatAcceptedCharactersLength,
event.cwsprChatAcceptedNumberOfLines
)
codeWhispererClient
.sendTelemetryEvent({
telemetryEvent: {
Expand Down

0 comments on commit ad0e018

Please sign in to comment.