Skip to content

Commit bdf370a

Browse files
authored
telemetry(vscode): MetricBase.reasonDesc #764
Problem: In the generated `telemetry.gen.ts` for vscode toolkit, `MetricBase` does not have various common fields. This adds friction when setting these fields. Solution: Update the generator to define `MetricBase.reasonDesc`.
1 parent 867fff1 commit bdf370a

File tree

8 files changed

+38
-14
lines changed

8 files changed

+38
-14
lines changed

buildspec/nodeTests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 0.2
33
phases:
44
install:
55
runtime-versions:
6-
nodejs: 14
6+
nodejs: 22
77

88
build:
99
commands:

telemetry/vscode/README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@ This package contains scripts and files to generate telemetry calls for:
66

77
## Usage
88

9-
To generate telemetry for VSCode, install this package in your package.json, then run:
9+
To generate telemetry and see the result:
1010

11-
`node node_modules/@aws-toolkits/telemetry/lib/generateTelemetry.js --output=<path/to/file>.ts`
11+
1. run `npm run build` to produce the `lib/` dir.
12+
2. run:
13+
```
14+
node ./lib/generateTelemetry.js --output=telemetry.gen.ts
15+
```
16+
- The script has two arguments:
17+
1. `--extraInput` list of paths to telemetry JSON files, seperated by commas. For example, "--extraInput=abc.json,/abc/bcd.json"
18+
2. `--output` path where the final output will go. For example, "--output=abc.ts"
1219

13-
The script has two arguments:
20+
To generate telemetry for VSCode from a downstream project,
1421

15-
1. `--extraInput` accepts lists of paths to telemetry JSON files, seperated by commas. For example, "--extraInput=abc.json,/abc/bcd.json"
16-
2. `--output` accepts one path which represents where the final output will go. For example, "--output=abc.ts"
22+
1. install this package in your package.json
23+
2. run:
24+
```
25+
node node_modules/@aws-toolkits/telemetry/lib/generateTelemetry.js --output=<path/to/file>.ts
26+
```

telemetry/vscode/src/generate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function getTypeOrThrow(types: MetadataType[] = [], name: string) {
114114
}
115115

116116
const baseName = 'MetricBase'
117-
const commonMetadata = ['result', 'reason', 'duration']
117+
const commonMetadata = ['result', 'reason', 'reasonDesc', 'duration']
118118
const passive: PropertySignatureStructure = {
119119
isReadonly: true,
120120
hasQuestionToken: true,

telemetry/vscode/test/generator.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ describe('Generator', () => {
1313
tempDir = tmpdir()
1414
})
1515

16-
test('Generate fails when validation fails', async () => {
16+
test('validation', async () => {
1717
await expect(testGenerator(['resources/invalidInput.json'], '/invalid/file/path')).rejects.toBeDefined()
1818
})
1919

20-
test('Generates with normal input', async () => {
20+
test('with normal input', async () => {
2121
await testGenerator([`resources/generatorInput.json`], `resources/generatorOutput.ts`)
2222
})
2323

24-
test('Generate overrides', async () => {
24+
test('overrides', async () => {
2525
await testGenerator(
2626
['resources/testOverrideInput.json', 'resources/testResultInput.json'],
2727
'resources/generatorOverrideOutput.ts'

telemetry/vscode/test/resources/generatorInput.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
{
1515
"name": "reason",
1616
"type": "string",
17-
"description": "The reason for a metric or exception depending on context"
17+
"description": "Reason code or name for an event (when result=Succeeded) or error (when result=Failed). Unlike the `reasonDesc` field, this should be a stable/predictable name for a class of events or errors (typically the exception name, e.g. FileIOException)."
18+
},
19+
{
20+
"name": "reasonDesc",
21+
"type": "string",
22+
"description": "Error message detail. May contain arbitrary message details (unlike the `reason` field), but should be truncated (recommendation: 200 chars)."
1823
},
1924
{
2025
"name": "duration",

telemetry/vscode/test/resources/generatorOutput.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
export interface MetricBase {
66
/** The result of the operation */
77
readonly result?: Result
8-
/** The reason for a metric or exception depending on context */
8+
/** Reason code or name for an event (when result=Succeeded) or error (when result=Failed). Unlike the `reasonDesc` field, this should be a stable/predictable name for a class of events or errors (typically the exception name, e.g. FileIOException). */
99
readonly reason?: string
10+
/** Error message detail. May contain arbitrary message details (unlike the `reason` field), but should be truncated (recommendation: 200 chars). */
11+
readonly reasonDesc?: string
1012
/** The duration of the operation in miliseconds */
1113
readonly duration?: number
1214
/** A flag indicating that the metric was not caused by the user. */

telemetry/vscode/test/resources/generatorOverrideOutput.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
export interface MetricBase {
66
/** The result of the operation */
77
readonly result?: Result
8-
/** The reason for a metric or exception depending on context */
8+
/** Reason code or name for an event (when result=Succeeded) or error (when result=Failed). Unlike the `reasonDesc` field, this should be a stable/predictable name for a class of events or errors (typically the exception name, e.g. FileIOException). */
99
readonly reason?: string
10+
/** Error message detail. May contain arbitrary message details (unlike the `reason` field), but should be truncated (recommendation: 200 chars). */
11+
readonly reasonDesc?: string
1012
/** The duration of the operation in miliseconds */
1113
readonly duration?: number
1214
/** A flag indicating that the metric was not caused by the user. */

telemetry/vscode/test/resources/testOverrideInput.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
{
99
"name": "reason",
1010
"type": "string",
11-
"description": "The reason for a metric or exception depending on context"
11+
"description": "Reason code or name for an event (when result=Succeeded) or error (when result=Failed). Unlike the `reasonDesc` field, this should be a stable/predictable name for a class of events or errors (typically the exception name, e.g. FileIOException)."
12+
},
13+
{
14+
"name": "reasonDesc",
15+
"type": "string",
16+
"description": "Error message detail. May contain arbitrary message details (unlike the `reason` field), but should be truncated (recommendation: 200 chars)."
1217
},
1318
{
1419
"name": "duration",

0 commit comments

Comments
 (0)