15
15
16
16
using System ;
17
17
using System . Linq ;
18
+ using System . Text ;
18
19
using AWS . Lambda . Powertools . Common ;
19
20
using AWS . Lambda . Powertools . Tracing . Internal ;
20
21
using Moq ;
@@ -590,7 +591,8 @@ public void OnException_WhenTracerCaptureErrorEnvironmentVariableIsTrue_Captures
590
591
configurations . Setup ( c => c . TracerCaptureError ) . Returns ( true ) ;
591
592
var recorder = new Mock < IXRayRecorder > ( ) ;
592
593
var exception = new Exception ( "Test Exception" ) ;
593
-
594
+ var message = GetException ( exception ) ;
595
+
594
596
var handler = new TracingAspectHandler ( null , nameSpace , TracingCaptureMode . EnvironmentVariable ,
595
597
configurations . Object , recorder . Object ) ;
596
598
var eventArgs = new AspectEventArgs { Name = methodName } ;
@@ -604,7 +606,7 @@ public void OnException_WhenTracerCaptureErrorEnvironmentVariableIsTrue_Captures
604
606
v . AddMetadata (
605
607
It . Is < string > ( i => i == nameSpace ) ,
606
608
It . Is < string > ( i => i == $ "{ methodName } error") ,
607
- It . Is < Exception > ( i => i == exception
609
+ It . Is < string > ( i => i == message
608
610
)
609
611
) , Times . Once ) ;
610
612
}
@@ -650,7 +652,8 @@ public void OnException_WhenTracerCaptureModeIsError_CapturesError()
650
652
configurations . Setup ( c => c . TracingDisabled ) . Returns ( false ) ;
651
653
var recorder = new Mock < IXRayRecorder > ( ) ;
652
654
var exception = new Exception ( "Test Exception" ) ;
653
-
655
+ var message = GetException ( exception ) ;
656
+
654
657
var handler = new TracingAspectHandler ( null , nameSpace , TracingCaptureMode . Error ,
655
658
configurations . Object , recorder . Object ) ;
656
659
var eventArgs = new AspectEventArgs { Name = methodName } ;
@@ -664,7 +667,7 @@ public void OnException_WhenTracerCaptureModeIsError_CapturesError()
664
667
v . AddMetadata (
665
668
It . Is < string > ( i => i == nameSpace ) ,
666
669
It . Is < string > ( i => i == $ "{ methodName } error") ,
667
- It . Is < Exception > ( i => i == exception
670
+ It . Is < string > ( i => i == message
668
671
)
669
672
) , Times . Once ) ;
670
673
}
@@ -680,7 +683,8 @@ public void OnException_WhenTracerCaptureModeIsResponseAndError_CapturesError()
680
683
configurations . Setup ( c => c . TracingDisabled ) . Returns ( false ) ;
681
684
var recorder = new Mock < IXRayRecorder > ( ) ;
682
685
var exception = new Exception ( "Test Exception" ) ;
683
-
686
+ var message = GetException ( exception ) ;
687
+
684
688
var handler = new TracingAspectHandler ( null , nameSpace , TracingCaptureMode . ResponseAndError ,
685
689
configurations . Object , recorder . Object ) ;
686
690
var eventArgs = new AspectEventArgs { Name = methodName } ;
@@ -694,7 +698,7 @@ public void OnException_WhenTracerCaptureModeIsResponseAndError_CapturesError()
694
698
v . AddMetadata (
695
699
It . Is < string > ( i => i == nameSpace ) ,
696
700
It . Is < string > ( i => i == $ "{ methodName } error") ,
697
- It . Is < Exception > ( i => i == exception
701
+ It . Is < string > ( i => i == message
698
702
)
699
703
) , Times . Once ) ;
700
704
}
@@ -761,6 +765,28 @@ public void OnException_WhenTracerCaptureModeIsDisabled_DoesNotCaptureError()
761
765
762
766
#endregion
763
767
768
+ #region Utilities
769
+
770
+ static string GetException ( Exception exception )
771
+ {
772
+ var sb = new StringBuilder ( ) ;
773
+ sb . AppendLine ( $ "Exception type: { exception . GetType ( ) } ") ;
774
+ sb . AppendLine ( $ "Exception message: { exception . Message } ") ;
775
+ sb . AppendLine ( $ "Stack trace: { exception . StackTrace } ") ;
776
+
777
+ if ( exception . InnerException != null )
778
+ {
779
+ sb . AppendLine ( "---BEGIN InnerException--- " ) ;
780
+ sb . AppendLine ( $ "Exception type { exception . InnerException . GetType ( ) } ") ;
781
+ sb . AppendLine ( $ "Exception message: { exception . InnerException . Message } ") ;
782
+ sb . AppendLine ( $ "Stack trace: { exception . InnerException . StackTrace } ") ;
783
+ sb . AppendLine ( "---END Inner Exception" ) ;
784
+ }
785
+ return sb . ToString ( ) ;
786
+ }
787
+
788
+ #endregion
789
+
764
790
#region OnExit Tests
765
791
766
792
[ Fact ]
0 commit comments