slanatech / swagger-stats

API Observability. Trace API calls and Monitor API performance, health and usage statistics in Node.js Microservices.
https://swaggerstats.io/
MIT License
891 stars 136 forks source link

UnhandledPromiseRejectionWarning when accessing /metrics #132

Closed spijs closed 3 years ago

spijs commented 3 years ago

After running npm update and thus upgrading swagger-stats to the latest release I now get the following error when accessing /metrics. It seems to me like a dependency issue on your end, but according to Stackoverflow replacing .end with .send might already solve this issue. Reverting back to 0.95.18 did not solve the issue.

UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer. Received an instance of Promise
    at ServerResponse.end (_http_outgoing.js:759:13)
    at /usr/src/app/node_modules/swagger-stats/lib/swsInterface.js:212:13
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Running /metrics results in a timeout which breaks prometheus/grafana integrations.

sv2 commented 3 years ago

Starting with v0.95.19 prom-client is now peer dependency. Please try to add prom-client to the dependency in your package.json

spijs commented 3 years ago

Prom-client v13.1.0 was already added as a dependency in package.json. Otherwise the project wouldn't even build :). But it could of course be that this is the dependency that is causing the issue...

spijs commented 3 years ago

I've got a fix. Will create PR. Turns out the code was returning promises which is not / no longer supported.

sv2 commented 3 years ago

I see, metrics() returns Promise starting from prom-client 13 ... Thanks for PR !