@@ -31,6 +31,16 @@ class TestClass {
3131 syncMethodWithCustomHandler ( ) {
3232 return 'Custom Handler' ;
3333 }
34+
35+ @CaptureTimingWithStatsD ( )
36+ syncMethodWithError ( ) {
37+ throw new Error ( 'Sync error' ) ;
38+ }
39+
40+ @CaptureTimingWithStatsD ( )
41+ async asyncMethodWithError ( ) {
42+ throw new Error ( 'Async error' ) ;
43+ }
3444}
3545
3646describe ( 'CaptureTimingWithStatsD' , ( ) => {
@@ -54,6 +64,7 @@ describe('CaptureTimingWithStatsD', () => {
5464 expect . any ( Number ) ,
5565 {
5666 sourceClass : 'TestClass' ,
67+ error : 'false' ,
5768 }
5869 ) ;
5970 } ) ;
@@ -66,6 +77,7 @@ describe('CaptureTimingWithStatsD', () => {
6677 expect . any ( Number ) ,
6778 {
6879 sourceClass : 'TestClass' ,
80+ error : 'false' ,
6981 }
7082 ) ;
7183 } ) ;
@@ -75,4 +87,54 @@ describe('CaptureTimingWithStatsD', () => {
7587 expect ( mockCallback ) . toHaveBeenCalledTimes ( 1 ) ;
7688 expect ( mockCallback ) . toHaveBeenCalledWith ( expect . any ( Number ) ) ;
7789 } ) ;
90+
91+ it ( 'should track error=true for synchronous methods that throw' , ( ) => {
92+ expect ( ( ) => instance . syncMethodWithError ( ) ) . toThrow ( 'Sync error' ) ;
93+ expect ( mockStatsD . timing ) . toHaveBeenCalledTimes ( 2 ) ;
94+ expect ( mockStatsD . timing ) . toHaveBeenCalledWith (
95+ 'TestClass_syncMethodWithError' ,
96+ expect . any ( Number ) ,
97+ {
98+ sourceClass : 'TestClass' ,
99+ error : 'true' ,
100+ }
101+ ) ;
102+ } ) ;
103+
104+ it ( 'should track error=true for asynchronous methods that throw' , async ( ) => {
105+ await expect ( instance . asyncMethodWithError ( ) ) . rejects . toThrow ( 'Async error' ) ;
106+ expect ( mockStatsD . timing ) . toHaveBeenCalledTimes ( 2 ) ;
107+ expect ( mockStatsD . timing ) . toHaveBeenCalledWith (
108+ 'TestClass_asyncMethodWithError' ,
109+ expect . any ( Number ) ,
110+ {
111+ sourceClass : 'TestClass' ,
112+ error : 'true' ,
113+ }
114+ ) ;
115+ } ) ;
116+
117+ it ( 'should track error=false for successful synchronous methods' , ( ) => {
118+ instance . syncMethod ( ) ;
119+ expect ( mockStatsD . timing ) . toHaveBeenCalledWith (
120+ 'TestClass' ,
121+ expect . any ( Number ) ,
122+ {
123+ methodName : 'syncMethod' ,
124+ error : 'false' ,
125+ }
126+ ) ;
127+ } ) ;
128+
129+ it ( 'should track error=false for successful asynchronous methods' , async ( ) => {
130+ await instance . asyncMethod ( ) ;
131+ expect ( mockStatsD . timing ) . toHaveBeenCalledWith (
132+ 'TestClass' ,
133+ expect . any ( Number ) ,
134+ {
135+ methodName : 'asyncMethod' ,
136+ error : 'false' ,
137+ }
138+ ) ;
139+ } ) ;
78140} ) ;
0 commit comments