feat: add support for otel metrics (method 3)#215
Draft
FrenchGithubUser wants to merge 19 commits intomasterfrom
Draft
feat: add support for otel metrics (method 3)#215FrenchGithubUser wants to merge 19 commits intomasterfrom
FrenchGithubUser wants to merge 19 commits intomasterfrom
Conversation
Contributor
Author
|
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.