Skip to content

Commit ce99859

Browse files
authored
refactor: Move trackPerformance to a property on telemetry (aws#5472)
## Problem Cleanup how trackPerformance is used ## Solution aws/aws-toolkit-common#823
1 parent 8c55eb0 commit ce99859

File tree

7 files changed

+25
-45
lines changed

7 files changed

+25
-45
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"generateNonCodeFiles": "npm run generateNonCodeFiles -w packages/ --if-present"
4040
},
4141
"devDependencies": {
42-
"@aws-toolkits/telemetry": "^1.0.240",
42+
"@aws-toolkits/telemetry": "^1.0.247",
4343
"@playwright/browser-chromium": "^1.43.1",
4444
"@types/vscode": "^1.68.0",
4545
"@types/vscode-webview": "^1.57.1",

packages/core/src/shared/performance/performance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export class PerformanceTracker {
3535

3636
constructor(private readonly name: string) {}
3737

38-
static enabled(name: string, trackPerformance?: boolean): boolean {
39-
return name === 'function_call' && (trackPerformance ?? false) && !isWeb()
38+
static enabled(name: string, trackPerformance: boolean): boolean {
39+
return name === 'function_call' && trackPerformance && !isWeb()
4040
}
4141

4242
start() {

packages/core/src/shared/telemetry/spans.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ export type SpanOptions = {
9898
/** True if this span should emit its telemetry events. Defaults to true if undefined. */
9999
emit?: boolean
100100

101-
/** True if this span should emit performance metrics acquired when running the function. Defaults to false if undefined */
102-
trackPerformance?: boolean
103-
104101
/**
105102
* Adds a function entry to the span stack.
106103
*
@@ -137,7 +134,9 @@ export type SpanOptions = {
137134
*/
138135
export class TelemetrySpan<T extends MetricBase = MetricBase> {
139136
#startTime?: Date
140-
#options: SpanOptions
137+
#options: SpanOptions & {
138+
trackPerformance: boolean
139+
}
141140
#performance?: PerformanceTracker
142141

143142
private readonly state: Partial<T> = {}
@@ -162,7 +161,10 @@ export class TelemetrySpan<T extends MetricBase = MetricBase> {
162161
// do emit by default
163162
emit: options?.emit === undefined ? true : options.emit,
164163
functionId: options?.functionId,
165-
trackPerformance: PerformanceTracker.enabled(this.name, options?.trackPerformance),
164+
trackPerformance: PerformanceTracker.enabled(
165+
this.name,
166+
this.definition.trackPerformance && (options?.emit ?? false) // only track the performance if we are also emitting
167+
),
166168
}
167169
}
168170

packages/core/src/shared/telemetry/vscodeTelemetry.json

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,13 @@
88
{
99
"name": "documentFormat",
1010
"type": "string",
11-
"allowedValues": [
12-
"JSON, YAML"
13-
],
11+
"allowedValues": ["JSON, YAML"],
1412
"description": "SSM Create document format selection"
1513
},
1614
{
1715
"name": "ssmOperation",
1816
"type": "string",
19-
"allowedValues": [
20-
"Create",
21-
"Update"
22-
],
17+
"allowedValues": ["Create", "Update"],
2318
"description": "SSM Publish Document operation type"
2419
},
2520
{
@@ -45,11 +40,7 @@
4540
{
4641
"name": "cwsprChatTriggerInteraction",
4742
"type": "string",
48-
"allowedValues": [
49-
"hotkeys",
50-
"click",
51-
"contextMenu"
52-
],
43+
"allowedValues": ["hotkeys", "click", "contextMenu"],
5344
"description": "Identifies the specific interaction that opens the chat panel"
5445
},
5546
{
@@ -114,11 +105,7 @@
114105
{
115106
"name": "cwsprChatConversationType",
116107
"type": "string",
117-
"allowedValues": [
118-
"Chat",
119-
"Assign",
120-
"Transform"
121-
],
108+
"allowedValues": ["Chat", "Assign", "Transform"],
122109
"description": "Identifies the type of conversation"
123110
},
124111
{
@@ -245,12 +232,7 @@
245232
{
246233
"name": "cwsprChatCommandType",
247234
"type": "string",
248-
"allowedValues": [
249-
"clear",
250-
"help",
251-
"transform",
252-
"auth"
253-
],
235+
"allowedValues": ["clear", "help", "transform", "auth"],
254236
"description": "Type of chat command (/command) executed"
255237
},
256238
{
@@ -266,11 +248,7 @@
266248
{
267249
"name": "authStatus",
268250
"type": "string",
269-
"allowedValues": [
270-
"connected",
271-
"notConnected",
272-
"expired"
273-
],
251+
"allowedValues": ["connected", "notConnected", "expired"],
274252
"description": "Status of the an auth connection."
275253
},
276254
{
@@ -1129,7 +1107,8 @@
11291107
"required": true
11301108
}
11311109
],
1132-
"passive": true
1110+
"passive": true,
1111+
"trackPerformance": true
11331112
}
11341113
]
1135-
}
1114+
}

packages/core/src/shared/utilities/workspaceUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ export async function collectFiles(
386386
},
387387
{
388388
emit: true,
389-
trackPerformance: true,
390389
functionId: {
391390
name: 'collectFiles',
392391
},

packages/core/src/test/shared/telemetry/spans.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('TelemetrySpan', function () {
8080
it('records performance', function () {
8181
const { expectedCpuUsage, expectedHeapTotal } = stubPerformance(sandbox)
8282
const span = new TelemetrySpan('function_call', {
83-
trackPerformance: true,
83+
emit: true,
8484
})
8585
span.start()
8686
clock.tick(90)
@@ -276,7 +276,7 @@ describe('TelemetryTracer', function () {
276276
clock?.tick(90)
277277
},
278278
{
279-
trackPerformance: true,
279+
emit: true,
280280
}
281281
)
282282

0 commit comments

Comments
 (0)