@@ -116,53 +116,56 @@ export function sendTelemetryEvent<P extends IEventNamePropertyMapping, E extend
116
116
}
117
117
const reporter = getTelemetryReporter ( ) ;
118
118
const measures = typeof durationMs === 'number' ? { duration : durationMs } : durationMs ? durationMs : undefined ;
119
- let customProperties : Record < string , string > = { } ;
119
+ const customProperties : Record < string , string > = { } ;
120
120
const eventNameSent = eventName as string ;
121
121
122
- if ( ex ) {
123
- // When sending telemetry events for exceptions no need to send custom properties.
124
- // Else we have to review all properties every time as part of GDPR.
125
- // Assume we have 10 events all with their own properties.
126
- // As we have errors for each event, those properties are treated as new data items.
127
- // Hence they need to be classified as part of the GDPR process, and thats unnecessary and onerous.
128
- customProperties = { originalEventName : eventName as string } ;
129
- reporter . sendTelemetryException ( ex , customProperties , measures ) ;
130
- } else {
131
- if ( properties ) {
132
- const data = properties as any ;
133
- Object . getOwnPropertyNames ( data ) . forEach ( ( prop ) => {
134
- if ( data [ prop ] === undefined || data [ prop ] === null ) {
135
- return ;
136
- }
137
- try {
138
- // If there are any errors in serializing one property, ignore that and move on.
139
- // Else nothing will be sent.
140
- customProperties [ prop ] =
141
- typeof data [ prop ] === 'string'
142
- ? data [ prop ]
143
- : typeof data [ prop ] === 'object'
144
- ? 'object'
145
- : data [ prop ] . toString ( ) ;
146
- } catch ( ex ) {
147
- traceError ( `Failed to serialize ${ prop } for ${ eventName } ` , ex ) ;
148
- }
149
- } ) ;
150
- }
151
-
152
- // Add shared properties to telemetry props (we may overwrite existing ones).
153
- Object . assign ( customProperties , sharedProperties ) ;
154
-
155
- // Remove shared DS properties from core extension telemetry.
156
- Object . keys ( sharedProperties ) . forEach ( ( shareProperty ) => {
157
- if (
158
- customProperties [ shareProperty ] &&
159
- shareProperty . startsWith ( 'ds_' ) &&
160
- ! ( eventNameSent . startsWith ( 'DS_' ) || eventNameSent . startsWith ( 'DATASCIENCE' ) )
161
- ) {
162
- delete customProperties [ shareProperty ] ;
122
+ if ( properties ) {
123
+ const data = properties as any ;
124
+ Object . getOwnPropertyNames ( data ) . forEach ( ( prop ) => {
125
+ if ( data [ prop ] === undefined || data [ prop ] === null ) {
126
+ return ;
127
+ }
128
+ try {
129
+ // If there are any errors in serializing one property, ignore that and move on.
130
+ // Else nothing will be sent.
131
+ customProperties [ prop ] =
132
+ typeof data [ prop ] === 'string'
133
+ ? data [ prop ]
134
+ : typeof data [ prop ] === 'object'
135
+ ? 'object'
136
+ : data [ prop ] . toString ( ) ;
137
+ } catch ( ex ) {
138
+ traceError ( `Failed to serialize ${ prop } for ${ eventName } ` , ex ) ;
163
139
}
164
140
} ) ;
141
+ }
142
+
143
+ // Add shared properties to telemetry props (we may overwrite existing ones).
144
+ Object . assign ( customProperties , sharedProperties ) ;
145
+
146
+ // Remove shared DS properties from core extension telemetry.
147
+ Object . keys ( sharedProperties ) . forEach ( ( shareProperty ) => {
148
+ if (
149
+ customProperties [ shareProperty ] &&
150
+ shareProperty . startsWith ( 'ds_' ) &&
151
+ ! ( eventNameSent . startsWith ( 'DS_' ) || eventNameSent . startsWith ( 'DATASCIENCE' ) )
152
+ ) {
153
+ delete customProperties [ shareProperty ] ;
154
+ }
155
+ } ) ;
165
156
157
+ if ( ex ) {
158
+ const errorProps = {
159
+ errorName : ex . name ,
160
+ errorMessage : ex . message ,
161
+ errorStack : ex . stack ?? ''
162
+ } ;
163
+ Object . assign ( customProperties , errorProps ) ;
164
+
165
+ // To avoid hardcoding the names and forgetting to update later.
166
+ const errorPropNames = Object . getOwnPropertyNames ( errorProps ) ;
167
+ reporter . sendTelemetryErrorEvent ( eventNameSent , customProperties , measures , errorPropNames ) ;
168
+ } else {
166
169
reporter . sendTelemetryEvent ( eventNameSent , customProperties , measures ) ;
167
170
}
168
171
0 commit comments