From 5a0ca25d10dd0cc5fc9727258722301d7f3aa138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= <2493377+askpt@users.noreply.github.com> Date: Thu, 14 Dec 2023 15:39:35 +0000 Subject: [PATCH] Refactor metrics constants and attributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com> --- .../MetricsConstants.cs | 28 ++++++++--------- .../MetricsHook.cs | 30 +++++++++---------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/OpenFeature.Contrib.Hooks.Otel/MetricsConstants.cs b/src/OpenFeature.Contrib.Hooks.Otel/MetricsConstants.cs index 45883bb2..ac08edac 100644 --- a/src/OpenFeature.Contrib.Hooks.Otel/MetricsConstants.cs +++ b/src/OpenFeature.Contrib.Hooks.Otel/MetricsConstants.cs @@ -2,22 +2,22 @@ namespace OpenFeature.Contrib.Hooks.Otel { internal static class MetricsConstants { - internal const string UNIT = "double"; + internal const string Unit = "double"; - internal const string ACTIVE_COUNT_NAME = "feature_flag.evaluation_active_count"; - internal const string REQUESTS_TOTAL_NAME = "feature_flag.evaluation_requests_total"; - internal const string SUCCESS_TOTAL_NAME = "feature_flag.evaluation_success_total"; - internal const string ERROR_TOTAL_NAME = "feature_flag.evaluation_error_total"; + internal const string ActiveCountName = "feature_flag.evaluation_active_count"; + internal const string RequestsTotalName = "feature_flag.evaluation_requests_total"; + internal const string SuccessTotalName = "feature_flag.evaluation_success_total"; + internal const string ErrorTotalName = "feature_flag.evaluation_error_total"; - internal const string ACTIVE_DESCRIPTION = "active flag evaluations counter"; - internal const string REQUESTS_DESCRIPTION = "feature flag evaluation request counter"; - internal const string SUCCESS_DESCRIPTION = "feature flag evaluation success counter"; - internal const string ERROR_DESCRIPTION = "feature flag evaluation error counter"; + internal const string ActiveDescription = "active flag evaluations counter"; + internal const string RequestsDescription = "feature flag evaluation request counter"; + internal const string SuccessDescription = "feature flag evaluation success counter"; + internal const string ErrorDescription = "feature flag evaluation error counter"; - internal const string KEY_ATTR = "feature_flag.key"; - internal const string PROVIDER_NAME_ATTR = "feature_flag.provider_name"; - internal const string VARIANT_ATTR = "feature_flag.variant"; - internal const string REASON_ATTR = "feature_flag.reason"; - internal const string EXCEPTION_ATTR = "exception"; + internal const string KeyAttr = "feature_flag.key"; + internal const string ProviderNameAttr = "feature_flag.provider_name"; + internal const string VariantAttr = "feature_flag.variant"; + internal const string ReasonAttr = "feature_flag.reason"; + internal const string ExceptionAttr = "exception"; } } diff --git a/src/OpenFeature.Contrib.Hooks.Otel/MetricsHook.cs b/src/OpenFeature.Contrib.Hooks.Otel/MetricsHook.cs index aafdfdbc..400d5b27 100644 --- a/src/OpenFeature.Contrib.Hooks.Otel/MetricsHook.cs +++ b/src/OpenFeature.Contrib.Hooks.Otel/MetricsHook.cs @@ -29,10 +29,10 @@ public MetricsHook() { var meter = new Meter(InstrumentationName, InstrumentationVersion); - _evaluationActiveUpDownCounter = meter.CreateUpDownCounter(MetricsConstants.ACTIVE_COUNT_NAME, MetricsConstants.UNIT, MetricsConstants.ACTIVE_DESCRIPTION); - _evaluationRequestCounter = meter.CreateCounter(MetricsConstants.REQUESTS_TOTAL_NAME, MetricsConstants.UNIT, MetricsConstants.REQUESTS_DESCRIPTION); - _evaluationSuccessCounter = meter.CreateCounter(MetricsConstants.SUCCESS_TOTAL_NAME, MetricsConstants.UNIT, MetricsConstants.SUCCESS_DESCRIPTION); - _evaluationErrorCounter = meter.CreateCounter(MetricsConstants.ERROR_TOTAL_NAME, MetricsConstants.UNIT, MetricsConstants.ERROR_DESCRIPTION); + _evaluationActiveUpDownCounter = meter.CreateUpDownCounter(MetricsConstants.ActiveCountName, MetricsConstants.Unit, MetricsConstants.ActiveDescription); + _evaluationRequestCounter = meter.CreateCounter(MetricsConstants.RequestsTotalName, MetricsConstants.Unit, MetricsConstants.RequestsDescription); + _evaluationSuccessCounter = meter.CreateCounter(MetricsConstants.SuccessTotalName, MetricsConstants.Unit, MetricsConstants.SuccessDescription); + _evaluationErrorCounter = meter.CreateCounter(MetricsConstants.ErrorTotalName, MetricsConstants.Unit, MetricsConstants.ErrorDescription); } /// @@ -49,8 +49,8 @@ public override Task Before(HookContext context, IReadO { var tagList = new TagList { - { MetricsConstants.KEY_ATTR, context.FlagKey }, - { MetricsConstants.PROVIDER_NAME_ATTR, context.ProviderMetadata.Name } + { MetricsConstants.KeyAttr, context.FlagKey }, + { MetricsConstants.ProviderNameAttr, context.ProviderMetadata.Name } }; _evaluationActiveUpDownCounter.Add(1, tagList); @@ -74,10 +74,10 @@ public override Task After(HookContext context, FlagEvaluationDetails d { var tagList = new TagList { - { MetricsConstants.KEY_ATTR, context.FlagKey }, - { MetricsConstants.PROVIDER_NAME_ATTR, context.ProviderMetadata.Name }, - { MetricsConstants.VARIANT_ATTR, details.Variant ?? details.Value?.ToString() }, - { MetricsConstants.REASON_ATTR, details.Reason ?? "UNKNOWN" } + { MetricsConstants.KeyAttr, context.FlagKey }, + { MetricsConstants.ProviderNameAttr, context.ProviderMetadata.Name }, + { MetricsConstants.VariantAttr, details.Variant ?? details.Value?.ToString() }, + { MetricsConstants.ReasonAttr, details.Reason ?? "UNKNOWN" } }; _evaluationSuccessCounter.Add(1, tagList); @@ -99,9 +99,9 @@ public override Task Error(HookContext context, Exception error, IReadOnly { var tagList = new TagList { - { MetricsConstants.KEY_ATTR, context.FlagKey }, - { MetricsConstants.PROVIDER_NAME_ATTR, context.ProviderMetadata.Name }, - { MetricsConstants.EXCEPTION_ATTR, error?.Message ?? "Unknown error" } + { MetricsConstants.KeyAttr, context.FlagKey }, + { MetricsConstants.ProviderNameAttr, context.ProviderMetadata.Name }, + { MetricsConstants.ExceptionAttr, error?.Message ?? "Unknown error" } }; _evaluationErrorCounter.Add(1, tagList); @@ -121,8 +121,8 @@ public override Task Finally(HookContext context, IReadOnlyDictionary