Skip to content
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

docs: add observableGauge to the prometheus experimental example #4267

Merged
1 change: 1 addition & 0 deletions experimental/examples/prometheus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ If you are using the default configurations, the prometheus client will be avail

<p align="center"><img src="images/prom-counter.png?raw=true"/></p>
<p align="center"><img src="images/prom-updowncounter.png?raw=true"/></p>
<p align="center"><img src="images/prom-gauge.png?raw=true"/></p>

## Useful links

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions experimental/examples/prometheus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ observableCounter.addCallback(observableResult => {
observableResult.observe(counter, attributes);
});

const randomMetricPromise = async () =>
new Promise(resolve =>
setTimeout(resolve(Math.floor(Math.random() * 100)), 50)
);

const observableGauge = meter.createObservableGauge(
'observable_gauge_requests',
{
description: 'Example of an ObservableGauge',
}
);
// Callbacks are run when metrics are scraped
observableGauge.addCallback(async observableResult => {
const value = await randomMetricPromise();
observableResult.observe(value, attributes);
});
Comment on lines +54 to +57
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, why not observe the value synchronously here? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, why not observe the value synchronously here? 🤔

Often, when I had to observe a value at querying time, it was from an async process, so I just replicated what I often deal with :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the ability to collect gauge asynchronously can be a good point to present in the example.


// Record metrics
setInterval(() => {
counter++;
Expand Down
Loading