Skip to content

Commit 30f9289

Browse files
authored
telemetry(ec2): remote VSCode connection #3723
1 parent d4d1ae0 commit 30f9289

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

packages/core/src/awsService/ec2/activation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export async function activate(ctx: ExtContext): Promise<void> {
4444
}),
4545

4646
Commands.register('aws.ec2.openRemoteConnection', async (node?: Ec2Node) => {
47-
await openRemoteConnection(connectionManagers, node)
47+
await telemetry.ec2_connectToInstance.run(async (span) => {
48+
span.record({ ec2ConnectionType: 'remoteWorkspace' })
49+
await openRemoteConnection(connectionManagers, node)
50+
})
4851
}),
4952

5053
Commands.register('aws.ec2.startInstance', async (node?: Ec2Node) => {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import * as vscode from 'vscode'
6+
import * as sinon from 'sinon'
7+
import { assertTelemetry } from '../../testUtil'
8+
import { Ec2InstanceNode } from '../../../awsService/ec2/explorer/ec2InstanceNode'
9+
import { Ec2ParentNode } from '../../../awsService/ec2/explorer/ec2ParentNode'
10+
import { Ec2Client } from '../../../shared/clients/ec2Client'
11+
import { Ec2Connecter } from '../../../awsService/ec2/model'
12+
import { PollingSet } from '../../../shared/utilities/pollingSet'
13+
14+
describe('ec2 activation', function () {
15+
let testNode: Ec2InstanceNode
16+
17+
before(function () {
18+
const testRegion = 'test-region'
19+
const testPartition = 'test-partition'
20+
// Don't want to be polling here, that is tested in ../ec2ParentNode.test.ts
21+
// disabled here for convenience (avoiding race conditions with timeout)
22+
sinon.stub(PollingSet.prototype, 'start')
23+
const testClient = new Ec2Client(testRegion)
24+
const parentNode = new Ec2ParentNode(testRegion, testPartition, new Ec2Client(testRegion))
25+
testNode = new Ec2InstanceNode(parentNode, testClient, testRegion, testPartition, {
26+
InstanceId: 'testId',
27+
LastSeenStatus: 'status',
28+
})
29+
})
30+
31+
after(function () {
32+
sinon.restore()
33+
})
34+
35+
it('telemetry', async function () {
36+
const terminalStub = sinon.stub(Ec2Connecter.prototype, 'attemptToOpenEc2Terminal')
37+
await vscode.commands.executeCommand('aws.ec2.openTerminal', testNode)
38+
39+
assertTelemetry('ec2_connectToInstance', { ec2ConnectionType: 'ssm' })
40+
terminalStub.restore()
41+
42+
const stopInstanceStub = sinon.stub(Ec2Client.prototype, 'stopInstanceWithCancel')
43+
await vscode.commands.executeCommand('aws.ec2.stopInstance', testNode)
44+
45+
assertTelemetry('ec2_changeState', { ec2InstanceState: 'stop' })
46+
stopInstanceStub.restore()
47+
})
48+
})

0 commit comments

Comments
 (0)