@@ -303,27 +303,25 @@ private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string,
303
303
eventProperties . Add ( "interval" , ( ( TimeSpan ) ( qos . StartTime - qos . PreviousEndTime ) ) . ToString ( "c" ) ) ;
304
304
}
305
305
306
- if ( ! qos . IsSuccess && qos . Exception ? . Data ? . Contains ( AzurePSErrorDataKeys . ErrorKindKey ) == true )
307
- {
308
- eventProperties . Add ( "pebcak" , ( qos . Exception . Data [ AzurePSErrorDataKeys . ErrorKindKey ] == ErrorKind . UserError ) . ToString ( ) ) ;
309
- }
310
-
311
306
if ( qos . Exception != null && populateException )
312
307
{
313
308
eventProperties [ "exception-type" ] = qos . Exception . GetType ( ) . ToString ( ) ;
309
+ string cloudErrorCode = null ;
314
310
if ( qos . Exception is CloudException cloudException )
315
311
{
316
312
eventProperties [ "exception-httpcode" ] = cloudException . Response ? . StatusCode . ToString ( ) ;
313
+ cloudErrorCode = cloudException . Body ? . Code ;
317
314
}
318
315
Exception innerException = qos . Exception . InnerException ;
319
316
List < Exception > innerExceptions = new List < Exception > ( ) ;
320
317
string innerExceptionStr = string . Empty ;
321
318
while ( innerException != null )
322
319
{
323
320
innerExceptions . Add ( innerException ) ;
324
- if ( innerException is CloudException )
321
+ if ( innerException is CloudException innerCloudException )
325
322
{
326
- eventProperties [ "exception-httpcode" ] = ( ( CloudException ) qos . Exception ) . Response ? . StatusCode . ToString ( ) ;
323
+ eventProperties [ "exception-httpcode" ] = innerCloudException . Response ? . StatusCode . ToString ( ) ;
324
+ cloudErrorCode = innerCloudException . Body ? . Code ;
327
325
}
328
326
innerException = innerException . InnerException ;
329
327
}
@@ -339,12 +337,33 @@ private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string,
339
337
eventProperties [ "exception-stack" ] = stack ;
340
338
}
341
339
340
+ if ( cloudErrorCode != null && ! ( qos . Exception . Data ? . Contains ( AzurePSErrorDataKeys . CloudErrorCodeKey ) == true ) )
341
+ {
342
+ qos . Exception . Data [ AzurePSErrorDataKeys . CloudErrorCodeKey ] = cloudErrorCode ;
343
+ }
344
+
342
345
if ( qos . Exception . Data != null )
343
346
{
344
347
if ( qos . Exception . Data . Contains ( AzurePSErrorDataKeys . HttpStatusCode ) )
345
348
{
346
349
eventProperties [ "exception-httpcode" ] = qos . Exception . Data [ AzurePSErrorDataKeys . HttpStatusCode ] . ToString ( ) ;
347
350
}
351
+
352
+ if ( qos . Exception . Data . Contains ( AzurePSErrorDataKeys . CloudErrorCodeKey ) == true )
353
+ {
354
+ string existingErrorKind = qos . Exception . Data . Contains ( AzurePSErrorDataKeys . ErrorKindKey )
355
+ ? qos . Exception . Data [ AzurePSErrorDataKeys . ErrorKindKey ] . ToString ( )
356
+ : null ;
357
+ cloudErrorCode = ( string ) qos . Exception . Data [ AzurePSErrorDataKeys . CloudErrorCodeKey ] ;
358
+ // For the time being, we consider ResourceNotFound and ResourceGroupNotFound as user's input error.
359
+ // We are considering if ResourceNotFound should be false positive error.
360
+ if ( ( "ResourceNotFound" . Equals ( cloudErrorCode ) || "ResourceGroupNotFound" . Equals ( cloudErrorCode ) )
361
+ && existingErrorKind != ErrorKind . FalseError )
362
+ {
363
+ qos . Exception . Data [ AzurePSErrorDataKeys . ErrorKindKey ] = ErrorKind . UserError ;
364
+ }
365
+ }
366
+
348
367
StringBuilder sb = new StringBuilder ( ) ;
349
368
foreach ( var key in qos . Exception . Data ? . Keys )
350
369
{
@@ -363,6 +382,20 @@ private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string,
363
382
eventProperties [ "exception-data" ] = sb . ToString ( ) ;
364
383
}
365
384
}
385
+ //We record the case which exception has no message
386
+ if ( string . IsNullOrEmpty ( qos . Exception . Message ) )
387
+ {
388
+ eventProperties [ "exception-emptymessage" ] = true . ToString ( ) ;
389
+ }
390
+
391
+ if ( ! qos . IsSuccess && qos . Exception ? . Data ? . Contains ( AzurePSErrorDataKeys . ErrorKindKey ) == true )
392
+ {
393
+ eventProperties [ "pebcak" ] = ( qos . Exception . Data [ AzurePSErrorDataKeys . ErrorKindKey ] == ErrorKind . UserError ) . ToString ( ) ;
394
+ if ( qos . Exception . Data [ AzurePSErrorDataKeys . ErrorKindKey ] == ErrorKind . FalseError )
395
+ {
396
+ eventProperties [ "IsSuccess" ] = true . ToString ( ) ;
397
+ }
398
+ }
366
399
}
367
400
368
401
if ( qos . InputFromPipeline != null )
0 commit comments