@@ -9,32 +9,37 @@ internal sealed class RedisMetrics
99{ 
1010    private  readonly  Meter  _meter ; 
1111    private  readonly  Counter < long >  _operationCount ; 
12-     //private readonly Counter<long> _completedAsynchronously; 
13-     //private readonly Counter<long> _completedSynchronously; 
14-     //private readonly Counter<long> _failedSynchronously; 
12+     private  readonly  Counter < long >  _completedAsynchronously ; 
13+     private  readonly  Counter < long >  _completedSynchronously ; 
14+     private  readonly  Counter < long >  _failedAsynchronously ; 
15+     private  readonly  Counter < long >  _failedSynchronously ; 
1516    private  readonly  Counter < long >  _nonPreferredEndpointCount ; 
1617
1718    public  static readonly  RedisMetrics  Instance  =  new  RedisMetrics ( ) ; 
1819
19-     public  RedisMetrics ( ) 
20+     private  RedisMetrics ( ) 
2021    { 
2122        _meter  =  new  Meter ( "StackExchange.Redis" ) ; 
2223
2324        _operationCount  =  _meter . CreateCounter < long > ( 
2425            "redis-operation-count" , 
2526            description :  "The number of operations performed." ) ; 
2627
27-         // _completedAsynchronously = _meter.CreateCounter<long>(
28-         //     "redis-completed-asynchronously",
29-         //     description: "The number of operations that have been completed asynchronously.");
28+         _completedAsynchronously  =  _meter . CreateCounter < long > ( 
29+             "redis-completed-asynchronously" , 
30+             description :  "The number of operations that have been completed asynchronously." ) ; 
3031
31-         // _completedSynchronously = _meter.CreateCounter<long>(
32-         //     "redis-completed-synchronously",
33-         //     description: "The number of operations that have been completed synchronously.");
32+         _completedSynchronously  =  _meter . CreateCounter < long > ( 
33+             "redis-completed-synchronously" , 
34+             description :  "The number of operations that have been completed synchronously." ) ; 
3435
35-         //_failedSynchronously = _meter.CreateCounter<long>( 
36-         //    "redis-failed-synchronously", 
37-         //    description: "The number of operations that failed to complete asynchronously."); 
36+         _failedAsynchronously  =  _meter . CreateCounter < long > ( 
37+             "redis-failed-asynchronously" , 
38+             description :  "The number of operations that failed to complete asynchronously." ) ; 
39+ 
40+         _failedSynchronously  =  _meter . CreateCounter < long > ( 
41+             "redis-failed-synchronously" , 
42+             description :  "The number of operations that failed to complete synchronously." ) ; 
3843
3944        _nonPreferredEndpointCount  =  _meter . CreateCounter < long > ( 
4045            "redis-non-preferred-endpoint-count" , 
@@ -50,6 +55,27 @@ public void IncrementOperationCount(string endpoint)
5055        } 
5156    } 
5257
58+     public  void  OnMessageComplete ( IResultBox ?  result ) 
59+     { 
60+         if  ( result  is  not null  && 
61+             ( _completedAsynchronously . Enabled  || 
62+             _completedSynchronously . Enabled  || 
63+             _failedAsynchronously . Enabled  || 
64+             _failedSynchronously . Enabled ) ) 
65+         { 
66+             Counter < long >  counter  =  ( result . IsFaulted ,  result . IsAsync )  switch 
67+             { 
68+                 ( false ,  true )  =>  _completedAsynchronously , 
69+                 ( false ,  false )  =>  _completedSynchronously , 
70+                 ( true ,  true )  =>  _failedAsynchronously , 
71+                 ( true ,  false )  =>  _failedSynchronously , 
72+             } ; 
73+ 
74+             // TODO: can we pass endpoint here? 
75+             counter . Add ( 1 ) ; 
76+         } 
77+     } 
78+ 
5379    public  void  IncrementNonPreferredEndpointCount ( string  endpoint ) 
5480    { 
5581        if  ( _nonPreferredEndpointCount . Enabled ) 
0 commit comments