Skip to content

Commit e665622

Browse files
authored
Merge pull request #4337 from aws/gajjardh/refactor-add-ComputeEnv-telemetry
WIP - added Compute Env to Post metrics
2 parents 36ed55c + 1e82a4e commit e665622

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

package-lock.json

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/toolkit/src/shared/telemetry/service-2.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@
6464
"type":"string",
6565
"max":2000
6666
},
67+
"ComputeEnv":{
68+
"type":"string",
69+
"enum":[
70+
"cloud9",
71+
"cloud9-codecatalyst",
72+
"codecatalyst",
73+
"ec2",
74+
"local",
75+
"sagemaker",
76+
"ssh",
77+
"test",
78+
"web",
79+
"wsl",
80+
"unknown"
81+
]
82+
},
6783
"Datapoint":{
6884
"type":"double",
6985
"min":0
@@ -169,6 +185,7 @@
169185
"AWSProductVersion":{"shape":"AWSProductVersion"},
170186
"OS":{"shape":"Value"},
171187
"OSVersion":{"shape":"Value"},
188+
"ComputeEnv": {"shape":"ComputeEnv"},
172189
"ParentProduct":{"shape":"Value"},
173190
"ParentProductVersion":{"shape":"Value"},
174191
"Metadata":{"shape":"Metadata"},
@@ -190,6 +207,7 @@
190207
"ClientID":{"shape":"ClientID"},
191208
"OS":{"shape":"Value"},
192209
"OSVersion":{"shape":"Value"},
210+
"ComputeEnv": {"shape":"ComputeEnv"},
193211
"ParentProduct":{"shape":"Value"},
194212
"ParentProductVersion":{"shape":"Value"},
195213
"MetricData":{"shape":"MetricData"}

packages/toolkit/src/shared/telemetry/telemetryClient.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ServiceConfigurationOptions } from 'aws-sdk/lib/service'
1717
import globals from '../extensionGlobals'
1818
import { DevSettings } from '../settings'
1919
import { ClassToInterfaceType } from '../utilities/tsUtils'
20+
import { getComputeEnvType } from './util'
2021

2122
export const accountMetadataKey = 'awsAccount'
2223
export const regionKey = 'awsRegion'
@@ -91,6 +92,7 @@ export class DefaultTelemetryClient implements TelemetryClient {
9192
ClientID: this.clientId,
9293
OS: os.platform(),
9394
OSVersion: os.release(),
95+
ComputeEnv: getComputeEnvType(),
9496
ParentProduct: vscode.env.appName,
9597
ParentProductVersion: vscode.version,
9698
MetricData: batch,
@@ -117,12 +119,14 @@ export class DefaultTelemetryClient implements TelemetryClient {
117119
AWSProductVersion: extensionVersion,
118120
OS: os.platform(),
119121
OSVersion: os.release(),
122+
ComputeEnv: getComputeEnvType(),
120123
ParentProduct: vscode.env.appName,
121124
ParentProductVersion: vscode.version,
122125
Comment: feedback.comment,
123126
Sentiment: feedback.sentiment,
124127
})
125128
.promise()
129+
this.logger.debug(`ComputeEnv detected for telemetry: ${getComputeEnvType()}`)
126130
this.logger.info('Successfully posted feedback')
127131
} catch (err) {
128132
this.logger.error(`Failed to post feedback: ${err}`)

packages/toolkit/src/shared/telemetry/util.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { mapMetadata } from './telemetryLogger'
1515
import { Result } from './telemetry.gen'
1616
import { MetricDatum } from './clienttelemetry'
1717
import { isValidationExemptMetric } from './exemptMetrics'
18+
import { isCloud9, isSageMaker } from '../../shared/extensionUtilities'
19+
import { isInDevEnv } from '../../codecatalyst/utils'
1820

1921
const legacySettingsTelemetryValueDisable = 'Disable'
2022
const legacySettingsTelemetryValueEnable = 'Enable'
@@ -90,6 +92,28 @@ export async function getUserAgent(
9092
return pairs.join(' ')
9193
}
9294

95+
type EnvType = 'cloud9' | 'cloud9-codecatalyst' | 'codecatalyst' | 'local' | 'ec2' | 'sagemaker' | 'test' | 'unknown'
96+
97+
export function getComputeEnvType(): EnvType {
98+
if (isCloud9('classic')) {
99+
return 'cloud9'
100+
} else if (isCloud9('codecatalyst')) {
101+
return 'cloud9-codecatalyst'
102+
} else if (isInDevEnv()) {
103+
return 'codecatalyst'
104+
} else if (isSageMaker()) {
105+
return 'sagemaker'
106+
} else if (env.remoteName === 'ssh-remote' && !isInDevEnv()) {
107+
return 'ec2'
108+
} else if (isAutomation()) {
109+
return 'test'
110+
} else if (!env.remoteName) {
111+
return 'local'
112+
} else {
113+
return 'unknown'
114+
}
115+
}
116+
93117
/**
94118
* Validates that emitted telemetry metrics
95119
* 1. contain a result property and

0 commit comments

Comments
 (0)