1515
1616using System ;
1717using System . Linq ;
18+ using System . Text ;
1819using AWS . Lambda . Powertools . Common ;
1920using AWS . Lambda . Powertools . Tracing . Internal ;
2021using Moq ;
@@ -590,7 +591,8 @@ public void OnException_WhenTracerCaptureErrorEnvironmentVariableIsTrue_Captures
590591 configurations . Setup ( c => c . TracerCaptureError ) . Returns ( true ) ;
591592 var recorder = new Mock < IXRayRecorder > ( ) ;
592593 var exception = new Exception ( "Test Exception" ) ;
593-
594+ var message = GetException ( exception ) ;
595+
594596 var handler = new TracingAspectHandler ( null , nameSpace , TracingCaptureMode . EnvironmentVariable ,
595597 configurations . Object , recorder . Object ) ;
596598 var eventArgs = new AspectEventArgs { Name = methodName } ;
@@ -604,7 +606,7 @@ public void OnException_WhenTracerCaptureErrorEnvironmentVariableIsTrue_Captures
604606 v . AddMetadata (
605607 It . Is < string > ( i => i == nameSpace ) ,
606608 It . Is < string > ( i => i == $ "{ methodName } error") ,
607- It . Is < Exception > ( i => i == exception
609+ It . Is < string > ( i => i == message
608610 )
609611 ) , Times . Once ) ;
610612 }
@@ -650,7 +652,8 @@ public void OnException_WhenTracerCaptureModeIsError_CapturesError()
650652 configurations . Setup ( c => c . TracingDisabled ) . Returns ( false ) ;
651653 var recorder = new Mock < IXRayRecorder > ( ) ;
652654 var exception = new Exception ( "Test Exception" ) ;
653-
655+ var message = GetException ( exception ) ;
656+
654657 var handler = new TracingAspectHandler ( null , nameSpace , TracingCaptureMode . Error ,
655658 configurations . Object , recorder . Object ) ;
656659 var eventArgs = new AspectEventArgs { Name = methodName } ;
@@ -664,7 +667,7 @@ public void OnException_WhenTracerCaptureModeIsError_CapturesError()
664667 v . AddMetadata (
665668 It . Is < string > ( i => i == nameSpace ) ,
666669 It . Is < string > ( i => i == $ "{ methodName } error") ,
667- It . Is < Exception > ( i => i == exception
670+ It . Is < string > ( i => i == message
668671 )
669672 ) , Times . Once ) ;
670673 }
@@ -680,7 +683,8 @@ public void OnException_WhenTracerCaptureModeIsResponseAndError_CapturesError()
680683 configurations . Setup ( c => c . TracingDisabled ) . Returns ( false ) ;
681684 var recorder = new Mock < IXRayRecorder > ( ) ;
682685 var exception = new Exception ( "Test Exception" ) ;
683-
686+ var message = GetException ( exception ) ;
687+
684688 var handler = new TracingAspectHandler ( null , nameSpace , TracingCaptureMode . ResponseAndError ,
685689 configurations . Object , recorder . Object ) ;
686690 var eventArgs = new AspectEventArgs { Name = methodName } ;
@@ -694,7 +698,7 @@ public void OnException_WhenTracerCaptureModeIsResponseAndError_CapturesError()
694698 v . AddMetadata (
695699 It . Is < string > ( i => i == nameSpace ) ,
696700 It . Is < string > ( i => i == $ "{ methodName } error") ,
697- It . Is < Exception > ( i => i == exception
701+ It . Is < string > ( i => i == message
698702 )
699703 ) , Times . Once ) ;
700704 }
@@ -761,6 +765,28 @@ public void OnException_WhenTracerCaptureModeIsDisabled_DoesNotCaptureError()
761765
762766 #endregion
763767
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+
764790 #region OnExit Tests
765791
766792 [ Fact ]
0 commit comments