@@ -98,31 +98,25 @@ export async function getUserAgent(
98
98
export function validateMetricEvent ( event : MetricDatum , fatal : boolean ) {
99
99
const failedStr : Result = 'Failed'
100
100
const telemetryRunDocsStr =
101
- 'Consider using `.run()` instead of `.emit()`, which will set these properties automatically. ' +
101
+ ' Consider using `.run()` instead of `.emit()`, which will set these properties automatically. ' +
102
102
'See https://github.com/aws/aws-toolkit-vscode/blob/master/docs/telemetry.md#guidelines'
103
103
104
104
if ( ! isValidationExemptMetric ( event . MetricName ) && event . Metadata ) {
105
105
const metadata = mapMetadata ( [ ] ) ( event . Metadata )
106
+ let msg = 'telemetry: invalid Metric: '
107
+
108
+ if ( metadata . result === undefined ) {
109
+ msg += `"${ event . MetricName } " emitted without the \`result\` property, which is always required.`
110
+ } else if ( metadata . result === failedStr && metadata . reason === undefined ) {
111
+ msg += `"${ event . MetricName } " emitted with result=Failed but without the \`reason\` property.`
112
+ } else {
113
+ return // Validation passed.
114
+ }
106
115
107
- try {
108
- if ( metadata . result === undefined ) {
109
- throw new Error (
110
- `Metric \`${ event . MetricName } \` was emitted without the \`result\` property. ` +
111
- `This property is always required. ${ telemetryRunDocsStr } `
112
- )
113
- }
114
-
115
- if ( metadata . result === failedStr && metadata . reason === undefined ) {
116
- throw new Error (
117
- `Metric \`${ event . MetricName } \` was emitted without the \`reason\` property. ` +
118
- `This property is always required when \`result\` = 'Failed'. ${ telemetryRunDocsStr } `
119
- )
120
- }
121
- } catch ( err : any ) {
122
- if ( fatal ) {
123
- throw err
124
- }
125
- getLogger ( ) . warn ( `Metric Event did not pass validation: ${ ( err as Error ) . message } ` )
116
+ msg += telemetryRunDocsStr
117
+ if ( fatal ) {
118
+ throw new Error ( msg )
126
119
}
120
+ getLogger ( ) . warn ( msg )
127
121
}
128
122
}
0 commit comments