prom-client icon indicating copy to clipboard operation
prom-client copied to clipboard

how to use opentelemetry-js/ with prom client?

Open RichardWright opened this issue 4 years ago • 5 comments

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!

RichardWright avatar Dec 18 '20 13:12 RichardWright

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
},

marcbachmann avatar Dec 25 '20 02:12 marcbachmann

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.

marcbachmann avatar Dec 25 '20 04:12 marcbachmann

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.

marcbachmann avatar Dec 30 '20 11:12 marcbachmann

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
},

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?

RichardWright avatar Feb 22 '21 22:02 RichardWright

@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?

RichardWright avatar Mar 08 '21 21:03 RichardWright