33using System . Diagnostics ;
44using System . Diagnostics . Metrics ;
55using System . Reflection ;
6+ using System . Threading ;
67using System . Threading . Tasks ;
78using OpenFeature . Model ;
89
@@ -36,17 +37,8 @@ public MetricsHook()
3637 _evaluationErrorCounter = meter . CreateCounter < long > ( MetricsConstants . ErrorTotalName , description : MetricsConstants . ErrorDescription ) ;
3738 }
3839
39- /// <summary>
40- /// Executes before the flag evaluation and captures metrics related to the evaluation.
41- /// The metrics are captured in the following order:
42- /// 1. The active count is incremented. (feature_flag.evaluation_active_count)
43- /// 2. The request count is incremented. (feature_flag.evaluation_requests_total)
44- /// </summary>
45- /// <typeparam name="T">The type of the flag value.</typeparam>
46- /// <param name="context">The hook context.</param>
47- /// <param name="hints">The optional hints.</param>
48- /// <returns>The evaluation context.</returns>
49- public override Task < EvaluationContext > Before < T > ( HookContext < T > context , IReadOnlyDictionary < string , object > hints = null )
40+ /// <inheritdoc/>
41+ public override ValueTask < EvaluationContext > BeforeAsync < T > ( HookContext < T > context , IReadOnlyDictionary < string , object > hints = null , CancellationToken cancellationToken = default )
5042 {
5143 var tagList = new TagList
5244 {
@@ -57,21 +49,12 @@ public override Task<EvaluationContext> Before<T>(HookContext<T> context, IReadO
5749 _evaluationActiveUpDownCounter . Add ( 1 , tagList ) ;
5850 _evaluationRequestCounter . Add ( 1 , tagList ) ;
5951
60- return base . Before ( context , hints ) ;
52+ return base . BeforeAsync ( context , hints ) ;
6153 }
6254
6355
64- /// <summary>
65- /// Executes after the flag evaluation and captures metrics related to the evaluation.
66- /// The metrics are captured in the following order:
67- /// 1. The success count is incremented. (feature_flag.evaluation_success_total)
68- /// </summary>
69- /// <typeparam name="T">The type of the flag value.</typeparam>
70- /// <param name="context">The hook context.</param>
71- /// <param name="details">The flag evaluation details.</param>
72- /// <param name="hints">The optional hints.</param>
73- /// <returns>The evaluation context.</returns>
74- public override Task After < T > ( HookContext < T > context , FlagEvaluationDetails < T > details , IReadOnlyDictionary < string , object > hints = null )
56+ /// <inheritdoc/>
57+ public override ValueTask AfterAsync < T > ( HookContext < T > context , FlagEvaluationDetails < T > details , IReadOnlyDictionary < string , object > hints = null , CancellationToken cancellationToken = default )
7558 {
7659 var tagList = new TagList
7760 {
@@ -83,20 +66,11 @@ public override Task After<T>(HookContext<T> context, FlagEvaluationDetails<T> d
8366
8467 _evaluationSuccessCounter . Add ( 1 , tagList ) ;
8568
86- return base . After ( context , details , hints ) ;
69+ return base . AfterAsync ( context , details , hints ) ;
8770 }
8871
89- /// <summary>
90- /// Executes when an error occurs during flag evaluation and captures metrics related to the error.
91- /// The metrics are captured in the following order:
92- /// 1. The error count is incremented. (feature_flag.evaluation_error_total)
93- /// </summary>
94- /// <typeparam name="T">The type of the flag value.</typeparam>
95- /// <param name="context">The hook context.</param>
96- /// <param name="error">The exception that occurred.</param>
97- /// <param name="hints">The optional hints.</param>
98- /// <returns>The evaluation context.</returns>
99- public override Task Error < T > ( HookContext < T > context , Exception error , IReadOnlyDictionary < string , object > hints = null )
72+ /// <inheritdoc/>
73+ public override ValueTask ErrorAsync < T > ( HookContext < T > context , Exception error , IReadOnlyDictionary < string , object > hints = null , CancellationToken cancellationToken = default )
10074 {
10175 var tagList = new TagList
10276 {
@@ -107,18 +81,11 @@ public override Task Error<T>(HookContext<T> context, Exception error, IReadOnly
10781
10882 _evaluationErrorCounter . Add ( 1 , tagList ) ;
10983
110- return base . Error ( context , error , hints ) ;
84+ return base . ErrorAsync ( context , error , hints ) ;
11185 }
11286
113- /// <summary>
114- /// Executes after the flag evaluation is complete and captures metrics related to the evaluation.
115- /// The active count is decremented. (feature_flag.evaluation_active_count)
116- /// </summary>
117- /// <typeparam name="T">The type of the flag value.</typeparam>
118- /// <param name="context">The hook context.</param>
119- /// <param name="hints">The optional hints.</param>
120- /// <returns>The evaluation context.</returns>
121- public override Task Finally < T > ( HookContext < T > context , IReadOnlyDictionary < string , object > hints = null )
87+ /// <inheritdoc/>
88+ public override ValueTask FinallyAsync < T > ( HookContext < T > context , IReadOnlyDictionary < string , object > hints = null , CancellationToken cancellationToken = default )
12289 {
12390 var tagList = new TagList
12491 {
@@ -128,7 +95,7 @@ public override Task Finally<T>(HookContext<T> context, IReadOnlyDictionary<stri
12895
12996 _evaluationActiveUpDownCounter . Add ( - 1 , tagList ) ;
13097
131- return base . Finally ( context , hints ) ;
98+ return base . FinallyAsync ( context , hints ) ;
13299 }
133100 }
134101}
0 commit comments