otel-utils 1.0.0__py3-none-any.whl → 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of otel-utils might be problematic. Click here for more details.
otel_utils/metrics.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from contextlib import contextmanager
|
|
2
2
|
from typing import Optional, Dict, Any, List
|
|
3
3
|
from opentelemetry import metrics
|
|
4
|
-
from opentelemetry.metrics import Observation, CallbackOptions
|
|
4
|
+
from opentelemetry.metrics import Observation, CallbackOptions, Counter, Histogram, _Gauge as Gauge
|
|
5
5
|
import time
|
|
6
6
|
|
|
7
7
|
|
|
@@ -13,9 +13,9 @@ class Metrics:
|
|
|
13
13
|
|
|
14
14
|
def __init__(self, service_name: str):
|
|
15
15
|
self._meter = metrics.get_meter(service_name)
|
|
16
|
-
self._gauges = {}
|
|
17
|
-
self._histograms = {}
|
|
18
|
-
self._counters = {}
|
|
16
|
+
self._gauges: Dict[str, Gauge] = {}
|
|
17
|
+
self._histograms: Dict[str, Histogram] = {}
|
|
18
|
+
self._counters: Dict[str, Counter] = {}
|
|
19
19
|
|
|
20
20
|
def create_histogram(
|
|
21
21
|
self,
|
|
@@ -109,4 +109,14 @@ class Metrics:
|
|
|
109
109
|
description=description,
|
|
110
110
|
unit=unit
|
|
111
111
|
)
|
|
112
|
-
return self._histograms[name]
|
|
112
|
+
return self._histograms[name]
|
|
113
|
+
|
|
114
|
+
def get_gauge(self, name: str, description: str = "", unit: str = "1"):
|
|
115
|
+
"""Gets or creates a gauge."""
|
|
116
|
+
if name not in self._gauges:
|
|
117
|
+
self._gauges[name] = self._meter.create_gauge(
|
|
118
|
+
name=name,
|
|
119
|
+
description=description,
|
|
120
|
+
unit=unit
|
|
121
|
+
)
|
|
122
|
+
return self._gauges[name]
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
otel_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
otel_utils/configurator.py,sha256=oq6OMt366xnWV5Qz-eu529MV4yks4Lclm_i2nzPGYR4,7483
|
|
3
3
|
otel_utils/logging.py,sha256=vWV60xD9_5Av7Y5q75Sp2wq4XrcHxC3XW16ETlDTw0c,5979
|
|
4
|
-
otel_utils/metrics.py,sha256=
|
|
4
|
+
otel_utils/metrics.py,sha256=vSe1vIPX88ws8qcP1anGvxMSbmp5owmdBgccnuq9tzo,4115
|
|
5
5
|
otel_utils/tracing.py,sha256=PtowQ7MvYld_xJlVAV4pBQuDBQIqPeP1FQPrzgZx9_Q,2625
|
|
6
|
-
otel_utils-1.
|
|
7
|
-
otel_utils-1.
|
|
8
|
-
otel_utils-1.
|
|
6
|
+
otel_utils-1.1.1.dist-info/METADATA,sha256=ZbXAcn3wHmvIg4M7D37Mx7sxuGQhJaFqpFGryVhFxyA,5278
|
|
7
|
+
otel_utils-1.1.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
8
|
+
otel_utils-1.1.1.dist-info/RECORD,,
|