Skip to content

Commit 60e8105

Browse files
authored
telemetry: "aws_openUrl" for URL click #3214
Extract openUrl() and use it from common places.
1 parent 4b94492 commit 60e8105

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

src/credentials/sso/model.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getLogger } from '../../shared/logger/logger'
1414
import { telemetry } from '../../shared/telemetry/telemetry'
1515
import { CancellationError } from '../../shared/utilities/timeoutUtils'
1616
import { ssoAuthHelpUrl } from '../../shared/constants'
17+
import { openUrl } from '../../shared/utilities/vsCodeUtils'
1718

1819
export interface SsoToken {
1920
/**
@@ -76,16 +77,8 @@ export interface SsoProfile {
7677

7778
export const builderIdStartUrl = 'https://view.awsapps.com/start'
7879

79-
const tryOpenHelpUrl = (url: string) =>
80-
telemetry.aws_openUrl
81-
.run(async span => {
82-
span.record({ url })
83-
const didOpen = await vscode.env.openExternal(vscode.Uri.parse(url))
84-
if (!didOpen) {
85-
throw new CancellationError('user')
86-
}
87-
})
88-
.catch(e => getLogger().verbose('auth: failed to open help URL: %s', e))
80+
const tryOpenHelpUrl = (url: vscode.Uri) =>
81+
openUrl(url).catch(e => getLogger().verbose('auth: failed to open help URL: %s', e))
8982

9083
export async function openSsoPortalLink(
9184
startUrl: string,

src/shared/constants.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const hostedFilesBaseUrl: string = 'https://d3rrggjwfhwld2.cloudfront.net
1616
export const endpointsFileUrl: string = 'https://idetoolkits.amazonwebservices.com/endpoints.json'
1717
export const aboutCredentialsFileUrl: string =
1818
'https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html'
19-
export const samAboutInstallUrl: string = 'https://aws.amazon.com/serverless/sam/'
19+
export const samAboutInstallUrl = vscode.Uri.parse('https://aws.amazon.com/serverless/sam/')
2020
export const vscodeMarketplaceUrl: string =
2121
'https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.aws-toolkit-vscode'
2222
export const githubUrl: string = 'https://github.com/aws/aws-toolkit-vscode'
@@ -30,7 +30,9 @@ export const documentationUrl: string = isCloud9()
3030
* - alternative?: codecatalyst/latest/userguide/sign-up-create-resources.html
3131
*/
3232
export const authHelpUrl = 'https://docs.aws.amazon.com/general/latest/gr/differences-aws_builder_id.html'
33-
export const ssoAuthHelpUrl = 'https://docs.aws.amazon.com/singlesignon/latest/userguide/howtosignin.html'
33+
export const ssoAuthHelpUrl = vscode.Uri.parse(
34+
'https://docs.aws.amazon.com/singlesignon/latest/userguide/howtosignin.html'
35+
)
3436
export const credentialHelpUrl: string =
3537
'https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/setup-credentials.html'
3638
export const ssoCredentialsHelpUrl: string =

src/shared/sam/cli/samCliDetection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function notifyUserSamCliNotDetected(SamCliSettings: SamCliSettings): void {
7171
)
7272
.then(async userResponse => {
7373
if (userResponse === learnMore) {
74-
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(samAboutInstallUrl))
74+
await vscode.commands.executeCommand('vscode.open', samAboutInstallUrl)
7575
} else if (userResponse === browseToSamCli) {
7676
const location: vscode.Uri[] | undefined = await vscode.window.showOpenDialog({
7777
canSelectFiles: true,

src/shared/sam/cli/samCliValidationNotification.ts

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

6+
import { openUrl } from '../../../shared/utilities/vsCodeUtils'
67
import * as vscode from 'vscode'
78
import * as nls from 'vscode-nls'
89

910
import { samAboutInstallUrl, vscodeMarketplaceUrl } from '../../constants'
1011
import { getIdeProperties } from '../../extensionUtilities'
11-
import { telemetry } from '../../telemetry/telemetry'
12-
import { CancellationError } from '../../utilities/timeoutUtils'
1312
import {
1413
InvalidSamCliError,
1514
InvalidSamCliVersionError,
@@ -31,13 +30,7 @@ export interface SamCliValidationNotificationAction {
3130
const actionGoToSamCli: SamCliValidationNotificationAction = {
3231
label: localize('AWS.samcli.userChoice.visit.install.url', 'Get SAM CLI'),
3332
invoke: async () => {
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-
})
33+
openUrl(samAboutInstallUrl)
4134
},
4235
}
4336

src/shared/sam/sync.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { getOverriddenParameters } from '../../lambda/config/parameterUtils'
4343
import { addTelemetryEnvVar } from './cli/samCliInvokerUtils'
4444
import { samSyncUrl, samInitDocUrl } from '../constants'
4545
import { getAwsConsoleUrl } from '../awsConsole'
46+
import { openUrl } from '../utilities/vsCodeUtils'
4647

4748
const localize = nls.loadMessageBundle()
4849

@@ -206,7 +207,7 @@ function createTemplatePrompter() {
206207
noItemsFoundItem: {
207208
label: localize('aws.sam.noWorkspace', 'No SAM template.yaml file(s) found. Select for help'),
208209
data: undefined,
209-
onClick: () => vscode.env.openExternal(samInitDocUrl),
210+
onClick: () => openUrl(samInitDocUrl),
210211
},
211212
})
212213
}

src/shared/ui/buttons.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { documentationUrl } from '../constants'
99
import { getIcon } from '../icons'
1010
import { WizardControl, WIZARD_EXIT, WIZARD_RETRY } from '../wizards/wizard'
1111
import { getIdeProperties } from '../extensionUtilities'
12+
import { openUrl } from '../utilities/vsCodeUtils'
1213

1314
const localize = nls.loadMessageBundle()
1415
const helpTooltip = localize('AWS.command.help', 'View Toolkit Documentation')
@@ -29,7 +30,6 @@ export interface QuickInputButton<T> extends vscode.QuickInputButton {
2930
*
3031
* @param uri Opens the URI upon clicking
3132
* @param tooltip Optional tooltip for button
32-
* @param url Optional URL to open when button is clicked
3333
*/
3434
export function createHelpButton(
3535
uri: string | vscode.Uri = documentationUrl,
@@ -52,7 +52,7 @@ export class QuickInputLinkButton implements QuickInputButton<void> {
5252
}
5353

5454
public onClick(): void {
55-
vscode.env.openExternal(this.uri)
55+
openUrl(this.uri)
5656
}
5757
}
5858

src/shared/utilities/vsCodeUtils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import * as nls from 'vscode-nls'
88
import { getIdeProperties } from '../extensionUtilities'
99
import * as pathutils from './pathUtils'
1010
import { getLogger } from '../logger/logger'
11-
import { Timeout, waitTimeout, waitUntil } from './timeoutUtils'
11+
import { CancellationError, Timeout, waitTimeout, waitUntil } from './timeoutUtils'
12+
import { telemetry } from '../telemetry/telemetry'
1213

1314
// TODO: Consider NLS initialization/configuration here & have packages to import localize from here
1415
export const localize = nls.loadMessageBundle()
@@ -162,3 +163,19 @@ export function reloadWindowPrompt(message: string): void {
162163
}
163164
})
164165
}
166+
167+
/**
168+
* Opens a URL in the system web browser. Throws `CancellationError`
169+
* if user dismisses the vscode confirmation prompt.
170+
*/
171+
export async function openUrl(url: vscode.Uri): Promise<boolean> {
172+
return telemetry.aws_openUrl.run(async span => {
173+
span.record({ url: url.toString() })
174+
const didOpen = await vscode.env.openExternal(url)
175+
if (!didOpen) {
176+
throw new CancellationError('user')
177+
// getLogger().verbose('failed to open URL: %s', e)
178+
}
179+
return didOpen
180+
})
181+
}

0 commit comments

Comments
 (0)