Skip to content

Commit c115e40

Browse files
authored
feat(telemetry): add attributes and increment (#3432)
## Problem * `spans.ts` can be simplified * Some telemetry/logging is too noisy * `vscode_executeCommand` is not a span ## Solution Change the behavior to make it less confusing. Spans are now more independent. It's also now possible to record information on all future spans bound to a context. ### Other Changes * Silence 4 CW commands that are triggered whenever auth changes * Remove throttle on `aws.auth.addConnection` * I'd like to remove the throttle on everything eventually
1 parent b0d1fe7 commit c115e40

File tree

19 files changed

+374
-288
lines changed

19 files changed

+374
-288
lines changed

package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,133 +3299,133 @@
32993299
"description": "AWS Contributed Icon",
33003300
"default": {
33013301
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3302-
"fontCharacter": "\\f1a5"
3302+
"fontCharacter": "\\f1aa"
33033303
}
33043304
},
33053305
"aws-cdk-logo": {
33063306
"description": "AWS Contributed Icon",
33073307
"default": {
33083308
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3309-
"fontCharacter": "\\f1a6"
3309+
"fontCharacter": "\\f1ab"
33103310
}
33113311
},
33123312
"aws-cloudformation-stack": {
33133313
"description": "AWS Contributed Icon",
33143314
"default": {
33153315
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3316-
"fontCharacter": "\\f1a7"
3316+
"fontCharacter": "\\f1ac"
33173317
}
33183318
},
33193319
"aws-cloudwatch-log-group": {
33203320
"description": "AWS Contributed Icon",
33213321
"default": {
33223322
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3323-
"fontCharacter": "\\f1a8"
3323+
"fontCharacter": "\\f1ad"
33243324
}
33253325
},
33263326
"aws-codecatalyst-logo": {
33273327
"description": "AWS Contributed Icon",
33283328
"default": {
33293329
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3330-
"fontCharacter": "\\f1a9"
3330+
"fontCharacter": "\\f1ae"
33313331
}
33323332
},
33333333
"aws-ecr-registry": {
33343334
"description": "AWS Contributed Icon",
33353335
"default": {
33363336
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3337-
"fontCharacter": "\\f1aa"
3337+
"fontCharacter": "\\f1af"
33383338
}
33393339
},
33403340
"aws-ecs-cluster": {
33413341
"description": "AWS Contributed Icon",
33423342
"default": {
33433343
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3344-
"fontCharacter": "\\f1ab"
3344+
"fontCharacter": "\\f1b0"
33453345
}
33463346
},
33473347
"aws-ecs-container": {
33483348
"description": "AWS Contributed Icon",
33493349
"default": {
33503350
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3351-
"fontCharacter": "\\f1ac"
3351+
"fontCharacter": "\\f1b1"
33523352
}
33533353
},
33543354
"aws-ecs-service": {
33553355
"description": "AWS Contributed Icon",
33563356
"default": {
33573357
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3358-
"fontCharacter": "\\f1ad"
3358+
"fontCharacter": "\\f1b2"
33593359
}
33603360
},
33613361
"aws-generic-attach-file": {
33623362
"description": "AWS Contributed Icon",
33633363
"default": {
33643364
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3365-
"fontCharacter": "\\f1ae"
3365+
"fontCharacter": "\\f1b3"
33663366
}
33673367
},
33683368
"aws-iot-certificate": {
33693369
"description": "AWS Contributed Icon",
33703370
"default": {
33713371
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3372-
"fontCharacter": "\\f1af"
3372+
"fontCharacter": "\\f1b4"
33733373
}
33743374
},
33753375
"aws-iot-policy": {
33763376
"description": "AWS Contributed Icon",
33773377
"default": {
33783378
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3379-
"fontCharacter": "\\f1b0"
3379+
"fontCharacter": "\\f1b5"
33803380
}
33813381
},
33823382
"aws-iot-thing": {
33833383
"description": "AWS Contributed Icon",
33843384
"default": {
33853385
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3386-
"fontCharacter": "\\f1b1"
3386+
"fontCharacter": "\\f1b6"
33873387
}
33883388
},
33893389
"aws-lambda-function": {
33903390
"description": "AWS Contributed Icon",
33913391
"default": {
33923392
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3393-
"fontCharacter": "\\f1b2"
3393+
"fontCharacter": "\\f1b7"
33943394
}
33953395
},
33963396
"aws-s3-bucket": {
33973397
"description": "AWS Contributed Icon",
33983398
"default": {
33993399
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3400-
"fontCharacter": "\\f1b3"
3400+
"fontCharacter": "\\f1b8"
34013401
}
34023402
},
34033403
"aws-s3-create-bucket": {
34043404
"description": "AWS Contributed Icon",
34053405
"default": {
34063406
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3407-
"fontCharacter": "\\f1b4"
3407+
"fontCharacter": "\\f1b9"
34083408
}
34093409
},
34103410
"aws-schemas-registry": {
34113411
"description": "AWS Contributed Icon",
34123412
"default": {
34133413
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3414-
"fontCharacter": "\\f1b5"
3414+
"fontCharacter": "\\f1ba"
34153415
}
34163416
},
34173417
"aws-schemas-schema": {
34183418
"description": "AWS Contributed Icon",
34193419
"default": {
34203420
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3421-
"fontCharacter": "\\f1b6"
3421+
"fontCharacter": "\\f1bb"
34223422
}
34233423
},
34243424
"aws-stepfunctions-preview": {
34253425
"description": "AWS Contributed Icon",
34263426
"default": {
34273427
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3428-
"fontCharacter": "\\f1b7"
3428+
"fontCharacter": "\\f1bc"
34293429
}
34303430
}
34313431
}

src/codecatalyst/commands.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const localize = nls.loadMessageBundle()
1010

1111
import * as vscode from 'vscode'
1212
import { selectCodeCatalystRepository, selectCodeCatalystResource } from './wizards/selectResource'
13-
import { openCodeCatalystUrl, recordSource } from './utils'
13+
import { openCodeCatalystUrl } from './utils'
1414
import { CodeCatalystAuthenticationProvider } from './auth'
1515
import { Commands } from '../shared/vscode/commands2'
1616
import { CodeCatalystClient, CodeCatalystResource, createClient } from '../shared/clients/codecatalystClient'
@@ -234,7 +234,7 @@ export class CodeCatalystCommands {
234234
}
235235

236236
public updateDevEnv(...args: WithClient<typeof updateDevEnv>) {
237-
telemetry.codecatalyst_updateDevEnvironmentSettings.record({
237+
telemetry.record({
238238
codecatalyst_updateDevEnvironmentLocationType: 'remote',
239239
})
240240

@@ -272,7 +272,7 @@ export class CodeCatalystCommands {
272272
// need to be careful of mapping explosion so this granular data would either need
273273
// to be flattened or we restrict the names to a pre-determined set
274274
if (id === undefined) {
275-
recordSource('CommandPalette')
275+
telemetry.record({ source: 'CommandPalette' })
276276
}
277277

278278
return this.withClient(openDevEnv, devenv, targetPath)

src/codecatalyst/reconnect.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import { showViewLogsMessage } from '../shared/utilities/messages'
1515
import { CodeCatalystAuthenticationProvider } from './auth'
1616
import { getCodeCatalystDevEnvId } from '../shared/vscode/env'
1717
import globals from '../shared/extensionGlobals'
18-
import { isDevenvVscode, recordSource } from './utils'
18+
import { isDevenvVscode } from './utils'
1919
import { SsoConnection } from '../credentials/auth'
20+
import { telemetry } from '../shared/telemetry/telemetry'
2021

2122
const localize = nls.loadMessageBundle()
2223

@@ -238,14 +239,16 @@ async function openReconnectedDevEnv(
238239
project: { name: devenv.projectName },
239240
}
240241

241-
recordSource('Reconnect')
242-
await codeCatalystConnectCommand.execute(client, identifier, devenv.previousVscodeWorkspace)
242+
await telemetry.runRoot(async () => {
243+
telemetry.record({ source: 'Reconnect' })
244+
await codeCatalystConnectCommand.execute(client, identifier, devenv.previousVscodeWorkspace)
243245

244-
// When we only have 1 devenv to watch we might as well close the local vscode instance
245-
if (closeRootInstance) {
246-
// A brief delay ensures that metrics are saved from the connect command
247-
sleep(5000).then(() => vscode.commands.executeCommand('workbench.action.closeWindow'))
248-
}
246+
// When we only have 1 devenv to watch we might as well close the local vscode instance
247+
if (closeRootInstance) {
248+
// A brief delay ensures that metrics are saved from the connect command
249+
sleep(5000).then(() => vscode.commands.executeCommand('workbench.action.closeWindow'))
250+
}
251+
})
249252
}
250253

251254
function getDevEnvName(alias: string | undefined, id: string) {

src/codecatalyst/uriHandlers.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@ import * as vscode from 'vscode'
77
import { SearchParams, UriHandler } from '../shared/vscode/uriHandler'
88
import { getCodeCatalystConfig } from '../shared/clients/codecatalystClient'
99
import { CodeCatalystCommands } from './commands'
10-
import { recordSource } from './utils'
1110

1211
export function register(
1312
handler: UriHandler,
1413
commands: Pick<typeof CodeCatalystCommands.declared, 'cloneRepo' | 'openDevEnv'>
1514
) {
1615
async function cloneHandler(params: ReturnType<typeof parseCloneParams>) {
17-
recordSource('UriHandler')
18-
1916
if (params.url.authority.endsWith(getCodeCatalystConfig().gitHostname)) {
2017
await commands.cloneRepo.execute(params.url)
2118
} else {
@@ -24,8 +21,6 @@ export function register(
2421
}
2522

2623
async function connectHandler(params: ReturnType<typeof parseConnectParams | typeof parseConnectParamsOld>) {
27-
recordSource('UriHandler')
28-
2924
await commands.openDevEnv.execute({
3025
id: params.devEnvironmentId,
3126
org: { name: 'spaceName' in params ? params.spaceName : params.organizationName },

src/codecatalyst/utils.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Ides } from 'aws-sdk/clients/codecatalyst'
77
import * as vscode from 'vscode'
88
import { CodeCatalystResource, getCodeCatalystConfig } from '../shared/clients/codecatalystClient'
99
import { pushIf } from '../shared/utilities/collectionUtils'
10-
import { telemetry } from '../shared/telemetry/telemetry'
1110

1211
/**
1312
* Builds a web URL from the given CodeCatalyst object.
@@ -56,9 +55,3 @@ export function openCodeCatalystUrl(o: CodeCatalystResource) {
5655
export function isDevenvVscode(ides: Ides | undefined): boolean {
5756
return ides !== undefined && ides.findIndex(ide => ide.name === 'VSCode') !== -1
5857
}
59-
60-
export function recordSource(source: 'Webview' | 'UriHandler' | 'Reconnect' | 'CommandPalette') {
61-
// TODO: add `source` (or something similar) as a base component to events
62-
telemetry.codecatalyst_connect.record({ source } as any)
63-
telemetry.codecatalyst_localClone.record({ source } as any)
64-
}

src/codecatalyst/vue/create/backend.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { CancellationError } from '../../../shared/utilities/timeoutUtils'
3232
import { isCloud9 } from '../../../shared/extensionUtilities'
3333
import { telemetry } from '../../../shared/telemetry/telemetry'
3434
import { isNonNullable } from '../../../shared/utilities/tsUtils'
35-
import { recordSource } from '../../utils'
3635
import { createOrgPrompter, createProjectPrompter } from '../../wizards/selectResource'
3736
import { GetSourceRepositoryCloneUrlsRequest } from 'aws-sdk/clients/codecatalyst'
3837
import { QuickPickPrompter } from '../../../shared/ui/pickerPrompter'
@@ -197,8 +196,10 @@ export class CodeCatalystCreateWebview extends VueWebview {
197196
}
198197
})()
199198

200-
recordSource('Webview')
201-
telemetry.codecatalyst_createDevEnvironment.record({ codecatalyst_createDevEnvironmentRepoType: source.type })
199+
telemetry.record({
200+
source: 'Webview',
201+
codecatalyst_createDevEnvironmentRepoType: source.type,
202+
})
202203

203204
this.onComplete(devenv)
204205
return devenv

src/codewhisperer/commands/basicCommands.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,12 @@ export const showFreeTierLimit = Commands.declare('aws.codeWhisperer.freeTierLim
132132
vscode.env.openExternal(vscode.Uri.parse(CodeWhispererConstants.learnMoreUri))
133133
})
134134

135-
export const updateReferenceLog = Commands.declare('aws.codeWhisperer.updateReferenceLog', () => () => {
136-
ReferenceLogViewProvider.instance.update()
137-
})
135+
export const updateReferenceLog = Commands.declare(
136+
{ id: 'aws.codeWhisperer.updateReferenceLog', logging: false },
137+
() => () => {
138+
ReferenceLogViewProvider.instance.update()
139+
}
140+
)
138141

139142
async function showCodeWhispererWelcomeMessage(context: ExtContext): Promise<void> {
140143
const filePath = isCloud9()
@@ -144,12 +147,15 @@ async function showCodeWhispererWelcomeMessage(context: ExtContext): Promise<voi
144147
await vscode.commands.executeCommand('markdown.showPreviewToSide', readmeUri)
145148
}
146149

147-
export const refreshStatusBar = Commands.declare('aws.codeWhisperer.refreshStatusBar', () => () => {
148-
if (AuthUtil.instance.isConnectionValid()) {
149-
InlineCompletionService.instance.setCodeWhispererStatusBarOk()
150-
} else if (AuthUtil.instance.isConnectionExpired()) {
151-
InlineCompletionService.instance.setCodeWhispererStatusBarDisconnected()
152-
} else {
153-
InlineCompletionService.instance.hideCodeWhispererStatusBar()
150+
export const refreshStatusBar = Commands.declare(
151+
{ id: 'aws.codeWhisperer.refreshStatusBar', logging: false },
152+
() => () => {
153+
if (AuthUtil.instance.isConnectionValid()) {
154+
InlineCompletionService.instance.setCodeWhispererStatusBarOk()
155+
} else if (AuthUtil.instance.isConnectionExpired()) {
156+
InlineCompletionService.instance.setCodeWhispererStatusBarDisconnected()
157+
} else {
158+
InlineCompletionService.instance.hideCodeWhispererStatusBar()
159+
}
154160
}
155-
})
161+
)

src/codewhisperer/explorer/codewhispererNode.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,17 @@ export class CodeWhispererNode implements RootNode {
102102
}
103103

104104
export const codewhispererNode = new CodeWhispererNode()
105-
export const refreshCodeWhisperer = Commands.register('aws.codeWhisperer.refresh', (showFreeTierLimitNode = false) => {
106-
codewhispererNode.updateShowFreeTierLimitReachedNode(showFreeTierLimitNode)
107-
codewhispererNode.refresh()
108-
})
105+
export const refreshCodeWhisperer = Commands.register(
106+
{ id: 'aws.codeWhisperer.refresh', logging: false },
107+
(showFreeTierLimitNode = false) => {
108+
codewhispererNode.updateShowFreeTierLimitReachedNode(showFreeTierLimitNode)
109+
codewhispererNode.refresh()
110+
}
111+
)
109112

110-
export const refreshCodeWhispererRootNode = Commands.register('aws.codeWhisperer.refreshRootNode', () => {
111-
codewhispererNode.refreshRootNode()
112-
})
113+
export const refreshCodeWhispererRootNode = Commands.register(
114+
{ id: 'aws.codeWhisperer.refreshRootNode', logging: false },
115+
() => {
116+
codewhispererNode.refreshRootNode()
117+
}
118+
)

src/credentials/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ Commands.register('aws.auth.signout', () => {
11641164
return signout(Auth.instance)
11651165
})
11661166

1167-
const addConnection = Commands.register('aws.auth.addConnection', async () => {
1167+
const addConnection = Commands.register({ id: 'aws.auth.addConnection', telemetryThrottleMs: false }, async () => {
11681168
const c9IamItem = createIamItem()
11691169
c9IamItem.detail =
11701170
'Activates working with resources in the Explorer. Requires an access key ID and secret access key.'

src/extension.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,16 @@ export async function activate(context: vscode.ExtensionContext) {
139139
awsFiletypes.activate()
140140

141141
globals.uriHandler = new UriHandler()
142-
context.subscriptions.push(vscode.window.registerUriHandler(globals.uriHandler))
142+
context.subscriptions.push(
143+
vscode.window.registerUriHandler({
144+
handleUri: uri =>
145+
telemetry.runRoot(() => {
146+
telemetry.record({ source: 'UriHandler' })
147+
148+
return globals.uriHandler.handleUri(uri)
149+
}),
150+
})
151+
)
143152

144153
const extContext: ExtContext = {
145154
extensionContext: context,
@@ -324,7 +333,7 @@ function recordToolkitInitialization(activationStartedOn: number, logger?: Logge
324333
*
325334
* Cloud9 does not show a progress notification.
326335
*/
327-
function wrapWithProgressForCloud9(channel: vscode.OutputChannel): typeof vscode.window['withProgress'] {
336+
function wrapWithProgressForCloud9(channel: vscode.OutputChannel): (typeof vscode.window)['withProgress'] {
328337
const withProgress = vscode.window.withProgress.bind(vscode.window)
329338

330339
return (options, task) => {

0 commit comments

Comments
 (0)