Getting an error when trying to access /metrics
Closed this issue · 3 comments
Hi!
When I try to access the /metrics
i get this error:
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Promise
at new NodeError (node:internal/errors:405:5)
at write_ (node:_http_outgoing:875:11)
at ServerResponse.end (node:_http_outgoing:1026:5)
at /<path>/test.js:15:7
at Layer.handle [as handle_request] (/<path>/node_modules/express/lib/router/layer.js:95:5)
at next (/h<path>/node_modules/express/lib/router/route.js:149:13)
at Route.dispatch (/<path>/node_modules/express/lib/router/route.js:119:3)
at Layer.handle [as handle_request] (/<path>/node_modules/express/lib/router/layer.js:95:5)
at /<path>/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/<path>/node_modules/express/lib/router/index.js:346:12)
After some research, I decided to try to create my own metrics integrations, when i started, I ended up getting the same error.
This time I wanted to try to understand the error, the error is basically saying that the function register.metrics()
(considering that the variable register
was created like: const register = new client.Registry();
), from the prom-client, is returning a promisse instead of a string, witch is making the http server give an error.
I solved the problem on my code by changing on the http server request to await for the register.metrics()
function, and my code started working again.
With this I'm thinking that in old versions of the prom-client the function register.metrics()
returned a string, but now returns a promisse.
The solution would be on the example on the readme change the /metrics
http request to be async and wait on promRegister.metrics()
.
fix for the README of the repository ( just replace the old "expose metrics endpoint" section with this)
// expose metrics endpoint
app.get('/metrics', async (req, res) => {
res.set('Content-Type', promRegister.contentType)
res.end(await promRegister.metrics())
})