Skip to content

Commit c788861

Browse files
committed
send null/undefined if default customization whose arn is empty string and will cause service throwing validation exception
1 parent 99ec961 commit c788861

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

packages/core/src/codewhisperer/client/codewhisperer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ export class DefaultCodeWhispererClient {
265265
}
266266
const response = await (await this.createUserSdkClient()).sendTelemetryEvent(requestWithCommonFields).promise()
267267
getLogger().debug(`codewhisperer: sendTelemetryEvent requestID: ${response.$response.requestId}`)
268+
269+
return response
268270
}
269271

270272
public async listFeatureEvaluations(): Promise<ListFeatureEvaluationsResponse> {

packages/core/src/codewhisperer/tracker/codewhispererTracker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import { InsertedCode } from '../../codewhispererChat/controllers/chat/model'
1515
import { codeWhispererClient } from '../client/codewhisperer'
1616
import { logSendTelemetryEventFailure } from '../../codewhispererChat/controllers/chat/telemetryHelper'
1717
import { Timeout } from '../../shared/utilities/timeoutUtils'
18-
import { activeCustomizationOrNull } from '../util/customizationUtil'
18+
import { getSelectedCustomization } from '../util/customizationUtil'
19+
import { undefinedIfEmpty } from '../../shared'
1920

2021
/**
2122
* This singleton class is mainly used for calculating the percentage of user modification.
@@ -89,7 +90,6 @@ export class CodeWhispererTracker {
8990

9091
public async emitTelemetryOnSuggestion(suggestion: AcceptedSuggestionEntry | InsertedCode) {
9192
let percentage = 1.0
92-
const customization = activeCustomizationOrNull()
9393

9494
try {
9595
if (suggestion.fileUrl?.scheme !== '') {
@@ -121,7 +121,7 @@ export class CodeWhispererTracker {
121121
conversationId: event.cwsprChatConversationId,
122122
messageId: event.cwsprChatMessageId,
123123
modificationPercentage: event.cwsprChatModificationPercentage,
124-
customizationArn: customization?.arn,
124+
customizationArn: undefinedIfEmpty(getSelectedCustomization().arn),
125125
},
126126
},
127127
})

packages/core/src/codewhisperer/util/customizationUtil.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,6 @@ export const getSelectedCustomization = (): Customization => {
122122
}
123123
}
124124

125-
// codewhisperer service will throw validation exception if arn is empty string, thus we need to specifically pass undefined if it's base customization
126-
export function activeCustomizationOrNull(): Customization | undefined {
127-
const customization = getSelectedCustomization()
128-
if (customization === baseCustomization) {
129-
return undefined
130-
}
131-
132-
return customization
133-
}
134-
135125
export const setSelectedCustomization = async (customization: Customization) => {
136126
if (!AuthUtil.instance.isValidEnterpriseSsoInUse() || !AuthUtil.instance.conn) {
137127
return

packages/core/src/codewhispererChat/controllers/chat/telemetryHelper.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import { isAwsError } from '../../../shared/errors'
3434
import { ChatMessageInteractionType } from '../../../codewhisperer/client/codewhispereruserclient'
3535
import { supportedLanguagesList } from '../chat/chatRequest/converter'
3636
import { AuthUtil } from '../../../codewhisperer/util/authUtil'
37-
import { activeCustomizationOrNull } from '../../../codewhisperer/util/customizationUtil'
37+
import { getSelectedCustomization } from '../../../codewhisperer/util/customizationUtil'
38+
import { undefinedIfEmpty } from '../../../shared'
3839

3940
export function logSendTelemetryEventFailure(error: any) {
4041
let requestId: string | undefined
@@ -259,7 +260,7 @@ export class CWCTelemetryHelper {
259260
acceptedLineCount: event.cwsprChatAcceptedNumberOfLines,
260261
acceptedSnippetHasReference: false,
261262
hasProjectLevelContext: this.responseWithProjectContext.get(event.cwsprChatMessageId),
262-
customizationArn: activeCustomizationOrNull()?.arn,
263+
customizationArn: undefinedIfEmpty(getSelectedCustomization().arn),
263264
},
264265
},
265266
})
@@ -383,7 +384,7 @@ export class CWCTelemetryHelper {
383384
hasProjectLevelContext: triggerPayload.relevantTextDocuments
384385
? triggerPayload.relevantTextDocuments.length > 0
385386
: false,
386-
customizationArn: activeCustomizationOrNull()?.arn,
387+
customizationArn: undefinedIfEmpty(getSelectedCustomization().arn),
387388
},
388389
},
389390
})

0 commit comments

Comments
 (0)