diff --git a/VERSION b/VERSION index 1454f6e..4d54dad 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.1 +4.0.2 diff --git a/src/utils/common.py b/src/utils/common.py index d79a66b..0c1ab88 100644 --- a/src/utils/common.py +++ b/src/utils/common.py @@ -89,3 +89,7 @@ def is_uuid (var): def is_not_uuid (var): return not is_uuid(var) + +_allowed_chars_pattern = re.compile(r'[^a-zA-Z0-9_\-\.]') +def sanitize_metric_name(name: str): + return re.sub(_allowed_chars_pattern, '_', name) diff --git a/src/utils/counter.py b/src/utils/counter.py index e0e50d9..0ea6bda 100644 --- a/src/utils/counter.py +++ b/src/utils/counter.py @@ -1,9 +1,11 @@ from prometheus_client import Counter from utils.cid import get_current_cid +from utils.common import sanitize_metric_name from utils.otel import get_otel_meter def create_counter(name, description): + name = sanitize_metric_name(name) return { 'otel': get_otel_meter().create_counter( name = name, diff --git a/src/utils/gauge.py b/src/utils/gauge.py index 7e116df..fde1e9e 100644 --- a/src/utils/gauge.py +++ b/src/utils/gauge.py @@ -3,12 +3,14 @@ from prometheus_client import Gauge from opentelemetry.metrics import Observation +from utils.common import sanitize_metric_name from utils.otel import get_otel_meter _numeric_value_pattern = r"-?\d+\.\d+" _current_gauge_values = {} def create_gauge(name, description): + name = sanitize_metric_name(name) _current_gauge_values[name] = 0.0 def observable_gauge_func(_):