diff --git a/src/OpenFeature.Contrib.Hooks.Otel/MetricsHook.cs b/src/OpenFeature.Contrib.Hooks.Otel/MetricsHook.cs index 5e5c8c31..aafdfdbc 100644 --- a/src/OpenFeature.Contrib.Hooks.Otel/MetricsHook.cs +++ b/src/OpenFeature.Contrib.Hooks.Otel/MetricsHook.cs @@ -8,6 +8,9 @@ namespace OpenFeature.Contrib.Hooks.Otel { + /// + /// Represents a hook for capturing metrics related to flag evaluations. + /// public class MetricsHook : Hook { private static readonly AssemblyName AssemblyName = typeof(MetricsHook).Assembly.GetName(); @@ -19,6 +22,9 @@ public class MetricsHook : Hook private readonly Counter _evaluationSuccessCounter; private readonly Counter _evaluationErrorCounter; + /// + /// Initializes a new instance of the class. + /// public MetricsHook() { var meter = new Meter(InstrumentationName, InstrumentationVersion); @@ -29,6 +35,16 @@ public MetricsHook() _evaluationErrorCounter = meter.CreateCounter(MetricsConstants.ERROR_TOTAL_NAME, MetricsConstants.UNIT, MetricsConstants.ERROR_DESCRIPTION); } + /// + /// Executes before the flag evaluation and captures metrics related to the evaluation. + /// The metrics are captured in the following order: + /// 1. The active count is incremented. (feature_flag.evaluation_active_count) + /// 2. The request count is incremented. (feature_flag.evaluation_requests_total) + /// + /// The type of the flag value. + /// The hook context. + /// The optional hints. + /// The evaluation context. public override Task Before(HookContext context, IReadOnlyDictionary hints = null) { var tagList = new TagList @@ -43,6 +59,17 @@ public override Task Before(HookContext context, IReadO return base.Before(context, hints); } + + /// + /// Executes after the flag evaluation and captures metrics related to the evaluation. + /// The metrics are captured in the following order: + /// 1. The success count is incremented. (feature_flag.evaluation_success_total) + /// + /// The type of the flag value. + /// The hook context. + /// The flag evaluation details. + /// The optional hints. + /// The evaluation context. public override Task After(HookContext context, FlagEvaluationDetails details, IReadOnlyDictionary hints = null) { var tagList = new TagList @@ -58,6 +85,16 @@ public override Task After(HookContext context, FlagEvaluationDetails d return base.After(context, details, hints); } + /// + /// Executes when an error occurs during flag evaluation and captures metrics related to the error. + /// The metrics are captured in the following order: + /// 1. The error count is incremented. (feature_flag.evaluation_error_total) + /// + /// The type of the flag value. + /// The hook context. + /// The exception that occurred. + /// The optional hints. + /// The evaluation context. public override Task Error(HookContext context, Exception error, IReadOnlyDictionary hints = null) { var tagList = new TagList @@ -72,6 +109,14 @@ public override Task Error(HookContext context, Exception error, IReadOnly return base.Error(context, error, hints); } + /// + /// Executes after the flag evaluation is complete and captures metrics related to the evaluation. + /// The active count is decremented. (feature_flag.evaluation_active_count) + /// + /// The type of the flag value. + /// The hook context. + /// The optional hints. + /// The evaluation context. public override Task Finally(HookContext context, IReadOnlyDictionary hints = null) { var tagList = new TagList