-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add support for otel metrics (method 3) #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
It appears that quite a few things are done one way with prometheus_client and another way with otel. Some of my findings:
meter.create_observable_gauge(callbacks=[
lambda options: [
Observation(
fn(),
attributes,
)
]
],)This also means that we have to create the gauge where we set the callbacks, we can't set them later
with backfill_processing_after_timer.labels(
**{SERVER_NAME_LABEL: self.server_name}
).time():
await long_process()this seems to be a decent equivalent: start = time.perf_counter()
await long_process()
backfill_processing_after_timer.record(
time.perf_counter() - start, {SERVER_NAME_LABEL: self.server_name}
)however, if
def _get_sample_with_name(self, metric: ObservableGauge, name: str) -> float:
"""For a prometheus metric get the value of the sample that has a
matching "name" label.
"""
for sample in next(iter(metric.collect())).samples:
if sample.labels.get("name") == name:
return sample.valueone way I tried doing it (not sure if it is properly functional) def _get_sample_with_name(self, metric: ObservableGauge, name: str) -> float:
"""For a prometheus metric get the value of the sample that has a
matching "name" label.
"""
for metric_family in REGISTRY.collect():
for sample in metric_family.samples:
if sample.labels.get("name") == name and sample.name == metric.name:
return sample.value
with self._number_in_flight_metric.track_inprogress():
return await make_deferred_yieldable(d)becomes something like: self._number_in_flight_metric.add(
1, {"name": self._name, SERVER_NAME_LABEL: self.server_name}
)
res = await make_deferred_yieldable(d)
self._number_in_flight_metric.add(
-1, {"name": self._name, SERVER_NAME_LABEL: self.server_name}
)
return resagain, the last |
73cf858 to
fd33875
Compare
03d5e24 to
112e279
Compare
No description provided.