Skip to content

Commit c48b64b

Browse files
authored
telemetry(sam): record when SAM CLI not installed #3131
Problem: We have a number of commands that require the SAM CLI. We are not tracking how often users fail these commands because they do not have SAM CLI installed. Solution: Add telemetry to track when this error is invoked.
1 parent 00d2e2e commit c48b64b

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

src/lambda/commands/createNewSamApp.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ import { checklogs } from '../../shared/localizedText'
4747
import globals from '../../shared/extensionGlobals'
4848
import { telemetry } from '../../shared/telemetry/telemetry'
4949
import { LambdaArchitecture, Result, Runtime } from '../../shared/telemetry/telemetry'
50-
51-
type CreateReason = 'unknown' | 'userCancelled' | 'fileNotFound' | 'complete' | 'error'
50+
import { getTelemetryReason, getTelemetryResult } from '../../shared/errors'
5251

5352
export const samInitTemplateFiles: string[] = ['template.yaml', 'template.yml']
5453
export const samInitReadmeFile: string = 'README.TOOLKIT.md'
@@ -59,7 +58,7 @@ export async function resumeCreateNewSamApp(
5958
activationReloadState: ActivationReloadState = new ActivationReloadState()
6059
) {
6160
let createResult: Result = 'Succeeded'
62-
let reason: CreateReason = 'complete'
61+
let reason: string | undefined
6362
let samVersion: string | undefined
6463
const samInitState: SamInitState | undefined = activationReloadState.getSamInitState()
6564
try {
@@ -134,7 +133,7 @@ export async function createNewSamApplication(
134133
const awsContext: AwsContext = extContext.awsContext
135134
const regionProvider: RegionProvider = extContext.regionProvider
136135
let createResult: Result = 'Succeeded'
137-
let reason: CreateReason = 'unknown'
136+
let reason: string | undefined
138137
let lambdaPackageType: 'Zip' | 'Image' | undefined
139138
let createRuntime: Runtime | undefined
140139
let samVersion: string | undefined
@@ -323,8 +322,8 @@ export async function createNewSamApplication(
323322
await vscode.workspace.openTextDocument(templateUri)
324323
}
325324
} catch (err) {
326-
createResult = 'Failed'
327-
reason = 'error'
325+
createResult = getTelemetryResult(err)
326+
reason = getTelemetryReason(err)
328327

329328
globals.outputChannel.show(true)
330329
getLogger('channel').error(

src/shared/sam/cli/samCliValidationNotification.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import * as nls from 'vscode-nls'
88

99
import { samAboutInstallUrl, vscodeMarketplaceUrl } from '../../constants'
1010
import { getIdeProperties } from '../../extensionUtilities'
11+
import { telemetry } from '../../telemetry/telemetry'
12+
import { CancellationError } from '../../utilities/timeoutUtils'
1113
import {
1214
InvalidSamCliError,
1315
InvalidSamCliVersionError,
@@ -29,7 +31,13 @@ export interface SamCliValidationNotificationAction {
2931
const actionGoToSamCli: SamCliValidationNotificationAction = {
3032
label: localize('AWS.samcli.userChoice.visit.install.url', 'Get SAM CLI'),
3133
invoke: async () => {
32-
await vscode.env.openExternal(vscode.Uri.parse(samAboutInstallUrl))
34+
telemetry.aws_openUrl.run(async span => {
35+
span.record({ url: samAboutInstallUrl })
36+
const didOpen = await vscode.env.openExternal(vscode.Uri.parse(samAboutInstallUrl))
37+
if (!didOpen) {
38+
throw new CancellationError('user')
39+
}
40+
})
3341
},
3442
}
3543

src/shared/sam/cli/samCliValidator.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as semver from 'semver'
88
import { ClassToInterfaceType } from '../../utilities/tsUtils'
99
import { SamCliSettings } from './samCliSettings'
1010
import { SamCliInfoInvocation, SamCliInfoResponse } from './samCliInfo'
11+
import { ToolkitError } from '../../errors'
1112

1213
export const minSamCliVersion = '0.47.0'
1314
export const minSamCliVersionForImageSupport = '1.13.0'
@@ -17,21 +18,17 @@ export const minSamCliVersionForArmSupport = '1.33.0'
1718
export const minSamCliVersionForDotnet31Support = '1.4.0'
1819

1920
// Errors
20-
export class InvalidSamCliError extends Error {
21-
public constructor(message?: string | undefined) {
22-
super(message)
23-
}
24-
}
21+
export class InvalidSamCliError extends ToolkitError {}
2522

2623
export class SamCliNotFoundError extends InvalidSamCliError {
2724
public constructor() {
28-
super('SAM CLI was not found')
25+
super('SAM CLI was not found', { code: 'MissingSamCli' })
2926
}
3027
}
3128

3229
export class InvalidSamCliVersionError extends InvalidSamCliError {
3330
public constructor(public versionValidation: SamCliVersionValidatorResult) {
34-
super('SAM CLI has an invalid version')
31+
super('SAM CLI has an invalid version', { code: 'InvalidSamCliVersion' })
3532
}
3633
}
3734

0 commit comments

Comments
 (0)