Skip to content

Commit fea962a

Browse files
committed
refactor: unify doc telemetry event handlers
1 parent 4ec1ecb commit fea962a

File tree

2 files changed

+9
-34
lines changed

2 files changed

+9
-34
lines changed

packages/core/src/amazonqDoc/controllers/chat/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ export class DocController {
603603
this.docGenerationTask.numberOfGeneratedFiles = totalGeneratedFiles
604604
const docGenerationEvent = this.docGenerationTask.docGenerationEventBase()
605605

606-
await session.sendDocGenerationTelemetryEvent(docGenerationEvent)
606+
await session.sendDocTelemetryEvent(docGenerationEvent, 'generation')
607607
}
608608
} finally {
609609
if (session?.state?.tokenSource?.token.isCancellationRequested) {
@@ -673,7 +673,7 @@ export class DocController {
673673
this.docGenerationTask.numberOfAddedFiles = totalAddedFiles
674674
const docAcceptanceEvent = this.docGenerationTask.docAcceptanceEventBase()
675675

676-
await session.sendDocAcceptanceTelemetryEvent(docAcceptanceEvent)
676+
await session.sendDocTelemetryEvent(docAcceptanceEvent, 'acceptance')
677677
}
678678
private processLink(message: any) {
679679
void openUrl(vscode.Uri.parse(message.link))

packages/core/src/amazonqDoc/session/session.ts

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,15 @@ export class Session {
247247
return { leftPath, rightPath, ...diff }
248248
}
249249

250-
public async sendDocGenerationTelemetryEvent(docV2GenerationEvent: DocV2GenerationEvent) {
250+
public async sendDocTelemetryEvent(
251+
telemetryEvent: DocV2GenerationEvent | DocV2AcceptanceEvent,
252+
eventType: 'generation' | 'acceptance'
253+
) {
251254
const client = await this.proxyClient.getClient()
252255
try {
253256
const params: SendTelemetryEventRequest = {
254257
telemetryEvent: {
255-
docV2GenerationEvent,
258+
[eventType === 'generation' ? 'docV2GenerationEvent' : 'docV2AcceptanceEvent']: telemetryEvent,
256259
},
257260
optOutPreference: getOptOutPreference(),
258261
userContext: {
@@ -263,42 +266,14 @@ export class Session {
263266
ideVersion: extensionVersion,
264267
},
265268
}
266-
const response = await client.sendTelemetryEvent(params).promise()
267-
getLogger().debug(
268-
`${featureName}: successfully sent docV2GenerationEvent: ConversationId: ${docV2GenerationEvent.conversationId} RequestId: ${response.$response.requestId}`
269-
)
270-
} catch (e) {
271-
getLogger().error(
272-
`${featureName}: failed to send doc generation telemetry: ${(e as Error).name}: ${
273-
(e as Error).message
274-
} RequestId: ${(e as any).requestId}`
275-
)
276-
}
277-
}
278269

279-
public async sendDocAcceptanceTelemetryEvent(docV2AcceptanceEvent: DocV2AcceptanceEvent) {
280-
const client = await this.proxyClient.getClient()
281-
try {
282-
const params: SendTelemetryEventRequest = {
283-
telemetryEvent: {
284-
docV2AcceptanceEvent,
285-
},
286-
optOutPreference: getOptOutPreference(),
287-
userContext: {
288-
ideCategory: 'VSCODE',
289-
operatingSystem: getOperatingSystem(),
290-
product: 'DocGeneration', // Should be the same as in JetBrains
291-
clientId: getClientId(globals.globalState),
292-
ideVersion: extensionVersion,
293-
},
294-
}
295270
const response = await client.sendTelemetryEvent(params).promise()
296271
getLogger().debug(
297-
`${featureName}: successfully sent docV2AcceptanceEvent: ConversationId: ${docV2AcceptanceEvent.conversationId} RequestId: ${response.$response.requestId}`
272+
`${featureName}: successfully sent docV2${eventType === 'generation' ? 'GenerationEvent' : 'AcceptanceEvent'}: ConversationId: ${telemetryEvent.conversationId} RequestId: ${response.$response.requestId}`
298273
)
299274
} catch (e) {
300275
getLogger().error(
301-
`${featureName}: failed to send doc generation telemetry: ${(e as Error).name}: ${
276+
`${featureName}: failed to send doc ${eventType} telemetry: ${(e as Error).name}: ${
302277
(e as Error).message
303278
} RequestId: ${(e as any).requestId}`
304279
)

0 commit comments

Comments
 (0)