@@ -80,15 +80,7 @@ public AzPredictorTelemetryClient(IAzContext azContext)
80
80
/// <inheritdoc/>
81
81
public void OnHistory ( HistoryTelemetryData telemetryData )
82
82
{
83
- if ( ! IsDataCollectionAllowed ( ) )
84
- {
85
- return ;
86
- }
87
-
88
- telemetryData . SessionId = SessionId ;
89
- telemetryData . CorrelationId = CorrelationId ;
90
-
91
- _telemetryDispatcher . Post ( telemetryData ) ;
83
+ PostTelemetryData ( telemetryData ) ;
92
84
93
85
#if TELEMETRY_TRACE && DEBUG
94
86
System . Diagnostics . Trace . WriteLine ( "Recording CommandHistory" ) ;
@@ -98,17 +90,7 @@ public void OnHistory(HistoryTelemetryData telemetryData)
98
90
/// <inheritdoc/>
99
91
public void OnRequestPrediction ( RequestPredictionTelemetryData telemetryData )
100
92
{
101
- if ( ! IsDataCollectionAllowed ( ) )
102
- {
103
- return ;
104
- }
105
-
106
- CorrelationId = Guid . NewGuid ( ) . ToString ( ) ;
107
-
108
- telemetryData . SessionId = SessionId ;
109
- telemetryData . CorrelationId = CorrelationId ;
110
-
111
- _telemetryDispatcher . Post ( telemetryData ) ;
93
+ PostTelemetryData ( telemetryData ) ;
112
94
113
95
#if TELEMETRY_TRACE && DEBUG
114
96
System . Diagnostics . Trace . WriteLine ( "Recording RequestPrediction" ) ;
@@ -118,15 +100,7 @@ public void OnRequestPrediction(RequestPredictionTelemetryData telemetryData)
118
100
/// <inheritdoc/>
119
101
public void OnSuggestionAccepted ( SuggestionAcceptedTelemetryData telemetryData )
120
102
{
121
- if ( ! IsDataCollectionAllowed ( ) )
122
- {
123
- return ;
124
- }
125
-
126
- telemetryData . SessionId = SessionId ;
127
- telemetryData . CorrelationId = CorrelationId ;
128
-
129
- _telemetryDispatcher . Post ( telemetryData ) ;
103
+ PostTelemetryData ( telemetryData ) ;
130
104
131
105
#if TELEMETRY_TRACE && DEBUG
132
106
System . Diagnostics . Trace . WriteLine ( "Recording AcceptSuggestion" ) ;
@@ -136,18 +110,20 @@ public void OnSuggestionAccepted(SuggestionAcceptedTelemetryData telemetryData)
136
110
/// <inheritdoc/>
137
111
public void OnGetSuggestion ( GetSuggestionTelemetryData telemetryData )
138
112
{
139
- if ( ! IsDataCollectionAllowed ( ) )
140
- {
141
- return ;
142
- }
113
+ PostTelemetryData ( telemetryData ) ;
143
114
144
- telemetryData . SessionId = SessionId ;
145
- telemetryData . CorrelationId = CorrelationId ;
115
+ #if TELEMETRY_TRACE && DEBUG
116
+ System . Diagnostics . Trace . WriteLine ( "Recording GetSuggestion" ) ;
117
+ #endif
118
+ }
146
119
147
- _telemetryDispatcher . Post ( telemetryData ) ;
120
+ /// <inheritdoc/>
121
+ public void OnLoadParameterMap ( ParameterMapTelemetryData telemetryData )
122
+ {
123
+ PostTelemetryData ( telemetryData ) ;
148
124
149
125
#if TELEMETRY_TRACE && DEBUG
150
- System . Diagnostics . Trace . WriteLine ( "Recording GetSuggestion " ) ;
126
+ System . Diagnostics . Trace . WriteLine ( "Recording LoadParameterMap " ) ;
151
127
#endif
152
128
}
153
129
@@ -165,6 +141,38 @@ private static bool IsDataCollectionAllowed()
165
141
return false ;
166
142
}
167
143
144
+ /// <summary>
145
+ /// Construct a string from an exception and the string is sent to telemetry.
146
+ /// The string should have minimum data that can help us to diagnose the exception
147
+ /// but not too excessive that may have PII.
148
+ /// </summary>
149
+ /// <param name="exception">The exception to construct the string from.</param>
150
+ /// <returns>A string to send to telemetry.</returns>
151
+ private static string FormatException ( Exception exception )
152
+ {
153
+ if ( exception == null )
154
+ {
155
+ return string . Empty ;
156
+ }
157
+
158
+ // The exception message may contain data such as file path if it is IO related exception.
159
+ // It's this solution to throw the exception, the type and the stack trace only contain information related to the solution.
160
+ return string . Format ( $ "Type: { exception . GetType ( ) . ToString ( ) } \n Stack Trace: { exception . StackTrace ? . ToString ( ) } ") ;
161
+ ; }
162
+
163
+ private void PostTelemetryData ( ITelemetryData telemetryData )
164
+ {
165
+ if ( ! IsDataCollectionAllowed ( ) )
166
+ {
167
+ return ;
168
+ }
169
+
170
+ telemetryData . SessionId = SessionId ;
171
+ telemetryData . CorrelationId = CorrelationId ;
172
+
173
+ _telemetryDispatcher . Post ( telemetryData ) ;
174
+ }
175
+
168
176
/// <summary>
169
177
/// Dispatches <see cref="ITelemetryData"/> according to its implementation.
170
178
/// </summary>
@@ -184,6 +192,9 @@ private void DispatchTelemetryData(ITelemetryData telemetryData)
184
192
case SuggestionAcceptedTelemetryData suggestionAccepted :
185
193
SendTelemetry ( suggestionAccepted ) ;
186
194
break ;
195
+ case ParameterMapTelemetryData parameterMap :
196
+ SendTelemetry ( parameterMap ) ;
197
+ break ;
187
198
default :
188
199
throw new NotImplementedException ( ) ;
189
200
}
@@ -210,7 +221,7 @@ private void SendTelemetry(RequestPredictionTelemetryData telemetryData)
210
221
var properties = CreateProperties ( telemetryData ) ;
211
222
properties . Add ( "Command" , telemetryData . Commands ?? string . Empty ) ;
212
223
properties . Add ( "HttpRequestSent" , telemetryData . HasSentHttpRequest . ToString ( CultureInfo . InvariantCulture ) ) ;
213
- properties . Add ( "Exception" , telemetryData . Exception ? . ToString ( ) ?? string . Empty ) ;
224
+ properties . Add ( "Exception" , AzPredictorTelemetryClient . FormatException ( telemetryData . Exception ) ) ;
214
225
215
226
_telemetryClient . TrackEvent ( $ "{ AzPredictorTelemetryClient . TelemetryEventPrefix } /RequestPrediction", properties ) ;
216
227
}
@@ -237,7 +248,7 @@ private void SendTelemetry(GetSuggestionTelemetryData telemetryData)
237
248
properties . Add ( "UserInput" , maskedUserInput ?? string . Empty ) ;
238
249
properties . Add ( "Suggestion" , sourceTexts != null ? JsonSerializer . Serialize ( sourceTexts . Zip ( suggestionSource ) . Select ( ( s ) => Tuple . Create ( s . First , s . Second ) ) , JsonUtilities . TelemetrySerializerOptions ) : string . Empty ) ;
239
250
properties . Add ( "IsCancelled" , telemetryData . IsCancellationRequested . ToString ( CultureInfo . InvariantCulture ) ) ;
240
- properties . Add ( "Exception" , telemetryData . Exception ? . ToString ( ) ?? string . Empty ) ;
251
+ properties . Add ( "Exception" , AzPredictorTelemetryClient . FormatException ( telemetryData . Exception ) ) ;
241
252
242
253
_telemetryClient . TrackEvent ( $ "{ AzPredictorTelemetryClient . TelemetryEventPrefix } /GetSuggestion", properties ) ;
243
254
}
@@ -258,6 +269,17 @@ private void SendTelemetry(SuggestionAcceptedTelemetryData telemetryData)
258
269
_telemetryClient . TrackEvent ( $ "{ AzPredictorTelemetryClient . TelemetryEventPrefix } /AcceptSuggestion", properties ) ;
259
270
}
260
271
272
+ /// <summary>
273
+ /// Sends the telemetry with the parameter map file loading information.
274
+ /// </summary>
275
+ private void SendTelemetry ( ParameterMapTelemetryData telemetryData )
276
+ {
277
+ var properties = CreateProperties ( telemetryData ) ;
278
+ properties . Add ( "Exception" , AzPredictorTelemetryClient . FormatException ( telemetryData . Exception ) ) ;
279
+
280
+ _telemetryClient . TrackEvent ( $ "{ AzPredictorTelemetryClient . TelemetryEventPrefix } /LoadParameterMap", properties ) ;
281
+ }
282
+
261
283
/// <summary>
262
284
/// Add the common properties to the telemetry event.
263
285
/// </summary>
0 commit comments