Skip to content

Commit d66f115

Browse files
ec2: add telemetry to connect flow. (#3611)
* add empty connect command * create sample QuickPick on click * hacky prompt + func to list instanceId * very hacky way to create prompt with instanceIds * move extractInstanceIds to own function * utilize lastTouchedRegion in prompt * throw cancellationError on user cancel * add a title to quickpick * refactor: increase testability * move test utility func to shared utility file * add general test cases for extractInstanceIdsFromReservations * add basic test for prompter * configure command to devMode * refactor to utilize wizard + integrate regionSubmenu * add new testing file * refactor to utilize regionSubmenu in isolation, rather than wrapped in Wizard class * fix awkward indent * add test file from feature/cwl branch * remove old prompter old + tests * delete tests that rely on feature/cwl changes * refactor to avoid circular dependency * fix improper headers + imports * introduce Ec2ConnectClient to handle connection * remove dead parameter * close connection on terminal close * add a little more to error msg * remove dead imports * log error to console * rename function Co-authored-by: Justin M. Keyes <[email protected]> * fix header Co-authored-by: Justin M. Keyes <[email protected]> * fix headers and imports * remove year from header * delete outdated test case * delete outdated test file * remove year from copyright header * fix formatting of files * remove alias in Ec2Instance * utilize interface for object-like shape * improve style + start of work on debugging error * make distinction between status error and permission error * start to add tests for error handling * move code to general Ec2Client * change Log Groups to selection in region submenu * refactor to avoid circular dependency * fix formatting * fix formatting * comment out the ec2Client we are not using * style fix * fix formatting * add test for error handling * fix formatting * add extra wrapper * generalize some code to a remoteSession file * add space between pieces * retrieve IAM role attached to instance when fails to connect * remove dead import * refactor to avoid circular dependency * checks if relevant policies are on attached role * use both probes to determine source of error * update tests * change callback to async/await * remove onError parameter and utilize .catch instead * add test for permissions detection * fix test * make error handling a try-catch * swap ec2Client to v3 * switch over SSM client * update tests and signatures for new error type in v3 * fix formatting * remove dead import * avoid unnecessary default prefix on client name Co-authored-by: Justin M. Keyes <[email protected]> * fix old import * refactor defaultEc2client -> ec2Client * rename Ec2ConnectClient * fix outdated imports in the test * add icons and detail to description * update tests to use sdk3 * update tests and function names * bubble error up * update test case * Remove please in text Co-authored-by: Justin M. Keyes <[email protected]> * Remove please in text in other error Co-authored-by: Justin M. Keyes <[email protected]> * remove unnecessary types and update tests to match * add match on detail, and instance id label * try to add telemetry * fix telemetry to fit other examples * fix telemetry * remove error suffix on error code * change language in error message * remove error suffix * remove manual recording + add await so that error is thrown properly --------- Co-authored-by: Justin M. Keyes <[email protected]>
1 parent 2cfe683 commit d66f115

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

src/ec2/activation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
import { ExtContext } from '../shared/extensions'
66
import { Commands } from '../shared/vscode/commands2'
77
import { tryConnect } from './commands'
8+
import { telemetry } from '../shared/telemetry/telemetry'
89

910
export async function activate(ctx: ExtContext): Promise<void> {
1011
ctx.extensionContext.subscriptions.push(
1112
Commands.register('aws.ec2.connectToInstance', async (param?: unknown) => {
12-
await tryConnect()
13+
await telemetry.ec2_connectToInstance.run(async span => {
14+
span.record({ ec2ConnectionType: 'ssm' })
15+
await tryConnect()
16+
})
1317
})
1418
)
1519
}

src/ec2/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { createEc2ConnectPrompter, handleEc2ConnectPrompterResponse } from './prompter'
77
import { isValidResponse } from '../shared/wizards/wizard'
88
import { Ec2ConnectionManager } from './model'
9+
import { CancellationError } from '../shared/utilities/timeoutUtils'
910

1011
export async function tryConnect(): Promise<void> {
1112
const prompter = createEc2ConnectPrompter()
@@ -15,5 +16,7 @@ export async function tryConnect(): Promise<void> {
1516
const selection = handleEc2ConnectPrompterResponse(response)
1617
const ec2Client = new Ec2ConnectionManager(selection.region)
1718
await ec2Client.attemptEc2Connection(selection)
19+
} else {
20+
throw new CancellationError('user')
1821
}
1922
}

src/ec2/model.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,15 @@ export class Ec2ConnectionManager {
8282
)
8383
}
8484

85-
throw new ToolkitError('Is SSM running on the target instance?', {
86-
code: 'EC2SSMConnect',
87-
documentationUri: vscode.Uri.parse(
88-
'https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started.html'
89-
),
90-
})
85+
throw new ToolkitError(
86+
'Ensure SSM is running on target instance. For more information see the documentation.',
87+
{
88+
code: 'EC2SSMConnect',
89+
documentationUri: vscode.Uri.parse(
90+
'https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started.html'
91+
),
92+
}
93+
)
9194
}
9295

9396
private async openSessionInTerminal(session: Session, selection: Ec2Selection) {

src/shared/clients/ssmClient.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { AWSError, SSM } from 'aws-sdk'
6+
import { SSM } from 'aws-sdk'
77
import { getLogger } from '../logger/logger'
8-
import { PromiseResult } from 'aws-sdk/lib/request'
98
import globals from '../extensionGlobals'
109

1110
export class SsmClient {
@@ -15,9 +14,7 @@ export class SsmClient {
1514
return await globals.sdkClientBuilder.createAwsService(SSM, undefined, this.regionCode)
1615
}
1716

18-
public async terminateSession(
19-
session: SSM.Session
20-
): Promise<void | PromiseResult<SSM.TerminateSessionResponse, AWSError>> {
17+
public async terminateSession(session: SSM.Session): Promise<SSM.TerminateSessionResponse> {
2118
const sessionId = session.SessionId!
2219
const client = await this.createSdkClient()
2320
const termination = await client
@@ -30,7 +27,7 @@ export class SsmClient {
3027
return termination!
3128
}
3229

33-
public async startSession(target: string): Promise<PromiseResult<SSM.StartSessionResponse, AWSError>> {
30+
public async startSession(target: string): Promise<SSM.StartSessionResponse> {
3431
const client = await this.createSdkClient()
3532
const response = await client.startSession({ Target: target }).promise()
3633
return response

src/shared/telemetry/vscodeTelemetry.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"types": [
3+
{
4+
"name": "ec2ConnectionType",
5+
"type": "string",
6+
"allowedValues": ["remoteDesktop", "ssh", "scp", "ssm"],
7+
"description": "Ec2 Connection Methods"
8+
},
39
{
410
"name": "codewhispererUserGroup",
511
"type": "string",

0 commit comments

Comments
 (0)