fix(observability): preserve event names and escape metric labels
This commit is contained in:
@@ -3,6 +3,10 @@ from collections import defaultdict
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
|
||||
def escape_label(value: str) -> str:
|
||||
return value.replace(chr(92), chr(92)*2).replace('"', chr(92)+'"').replace(chr(10), chr(92)+'n')
|
||||
|
||||
|
||||
class SimpleHistogram:
|
||||
"""
|
||||
Lightweight, thread-safe Prometheus-compatible histogram.
|
||||
@@ -136,13 +140,13 @@ class WorkerMetrics:
|
||||
lines.append("# TYPE cdr_processed_total counter")
|
||||
with self._lock:
|
||||
for (svc, rat), count in self._processed_total.items():
|
||||
lines.append(f'cdr_processed_total{{service_type="{svc}",radio_access_type="{rat}"}} {count}')
|
||||
lines.append(f'cdr_processed_total{{service_type="{escape_label(svc)}",radio_access_type="{escape_label(rat)}"}} {count}')
|
||||
|
||||
# 2. cdr_dlq_total
|
||||
lines.append("# HELP cdr_dlq_total Total CDRs routed to DLQ by reason")
|
||||
lines.append("# TYPE cdr_dlq_total counter")
|
||||
for reason, count in self._dlq_total.items():
|
||||
lines.append(f'cdr_dlq_total{{reason="{reason}"}} {count}')
|
||||
lines.append(f'cdr_dlq_total{{reason="{escape_label(reason)}"}} {count}')
|
||||
|
||||
# 3. Gauges
|
||||
lines.append("# HELP cdr_in_flight_buffer_size Current in-memory buffer size")
|
||||
|
||||
Reference in New Issue
Block a user