File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
libraries/tests/AWS.Lambda.Powertools.Metrics.Tests/Handlers Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -22,11 +22,22 @@ public Task<string> HandleDecoratorOutsideHandler(string input)
22
22
23
23
return Task . FromResult ( input . ToUpper ( CultureInfo . InvariantCulture ) ) ;
24
24
}
25
+
26
+ [ Metrics ( Namespace = "ns" , Service = "svc" ) ]
27
+ public Task < string > HandleDecoratorOutsideHandlerException ( string input )
28
+ {
29
+ MethodDecorated ( ) ;
30
+
31
+ Metrics . AddMetric ( $ "Metric Name", 1 , MetricUnit . Count ) ;
32
+
33
+ ThisThrowsDecorated ( ) ;
34
+
35
+ return Task . FromResult ( input . ToUpper ( CultureInfo . InvariantCulture ) ) ;
36
+ }
25
37
26
38
[ Metrics ( Namespace = "ns" , Service = "svc" ) ]
27
39
private void MethodDecorated ( )
28
40
{
29
- // NOOP
30
41
Metrics . AddMetric ( $ "Metric Name", 1 , MetricUnit . Count ) ;
31
42
Metrics . AddMetric ( $ "Metric Name Decorated", 1 , MetricUnit . Count ) ;
32
43
}
@@ -35,4 +46,10 @@ private void ThisThrows()
35
46
{
36
47
throw new NullReferenceException ( ) ;
37
48
}
49
+
50
+ [ Metrics ( Namespace = "ns" , Service = "svc" ) ]
51
+ private void ThisThrowsDecorated ( )
52
+ {
53
+ throw new NullReferenceException ( ) ;
54
+ }
38
55
}
Original file line number Diff line number Diff line change @@ -20,7 +20,21 @@ public async Task Stack_Trace_Included_When_Decorator_Present()
20
20
// Assert
21
21
var tracedException = await Assert . ThrowsAsync < NullReferenceException > ( Handle ) ;
22
22
Assert . StartsWith ( "at AWS.Lambda.Powertools.Metrics.Tests.Handlers.ExceptionFunctionHandler.ThisThrows()" , tracedException . StackTrace ? . TrimStart ( ) ) ;
23
+ }
24
+
25
+ [ Fact ]
26
+ public async Task Stack_Trace_Included_When_Decorator_Present_In_Method ( )
27
+ {
28
+ // Arrange
29
+ Metrics . ResetForTest ( ) ;
30
+ var handler = new ExceptionFunctionHandler ( ) ;
23
31
32
+ // Act
33
+ Task Handle ( ) => handler . HandleDecoratorOutsideHandlerException ( "whatever" ) ;
34
+
35
+ // Assert
36
+ var tracedException = await Assert . ThrowsAsync < NullReferenceException > ( Handle ) ;
37
+ Assert . StartsWith ( "at AWS.Lambda.Powertools.Metrics.Tests.Handlers.ExceptionFunctionHandler.__a$_around_ThisThrows" , tracedException . StackTrace ? . TrimStart ( ) ) ;
24
38
}
25
39
26
40
[ Fact ]
You can’t perform that action at this time.
0 commit comments