prom-client
prom-client copied to clipboard
how to use opentelemetry-js/ with prom client?
The memory/cpu statistics from this lib look great, but I'm already running a prometheus scrape endpoint. Is it possible to point prom client at an already running prometheus client?
Thanks!
I think it would make sense to completely migrate this module to the opentelemetry ecosystem.
Most metrics in this module would need to be re-implemented using the meter.createValueObserver gauge.
Just as heads up as I was a bit reading through their examples and source code: At the moment there's only a callback-based api to set a fixed value. The other native gauges they have only support increments & decrements.
To make a value setter accessible from outside the callback of their createValueObserver method, we would need to wrap the api a bit:
createValueObserver ({name, description}) {
let value
const observer = meter.createValueObserver(name, {description}, (observerResult) => {
if (value === undefined) return
observerResult.observe(value, {})
value = undefined
})
observer.observation = function (val) { value = val }
return observer
},
And here's a first working POC: https://github.com/marcbachmann/opentelemetry-node-metrics I have 3 TODO's in the code that might need some fixes.
While reading more source code, I found out that the .update only works when calling .bind first. Unlike as other metrics.
const meter = meter.createValueObserver(name, {description})
const instrument = meter.bind({some: 'label'})
// set the value with the labels above (serialization only happens once that way)
instrument.update(value)
I've migrated all the gauges in my repo and fixed the remaining issues. It's working properly and I've published the module to npm. I haven't worked on tests at the moment 😓. I'm interested in a response from somebody of the opentelemetry project in https://github.com/open-telemetry/opentelemetry-js/issues/623#issuecomment-751167041 to discuss how we should proceed on this.
I think it would make sense to completely migrate this module to the opentelemetry ecosystem.
Most metrics in this module would need to be re-implemented using the
meter.createValueObservergauge.Just as heads up as I was a bit reading through their examples and source code: At the moment there's only a callback-based api to set a fixed value. The other native gauges they have only support increments & decrements.
To make a value setter accessible from outside the callback of their
createValueObservermethod, we would need to wrap the api a bit:createValueObserver ({name, description}) { let value const observer = meter.createValueObserver(name, {description}, (observerResult) => { if (value === undefined) return observerResult.observe(value, {}) value = undefined }) observer.observation = function (val) { value = val } return observer },
I'm still quite new to this ecosystem - valueObserver is an awkward replacement for gauge, what do you feel prom client gains from being part of it?
@marcbachmann How is value observer used correctly in your examples? Values are histograms, not a substitue for a gauge, like in prom client.
Do you have some example output?