-
Notifications
You must be signed in to change notification settings - Fork 367
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
Hot Module Reload problem with prom-client #196
Comments
I have a similar problem when using express-prom-bundle and running my supertest tests via
|
I haven't used Webpack's HMR, but it looks like you might want to put that On principle I don't think there's a nice way for this to "just work." The registry (a singleton, if using the global reg) and metrics are both meant to be created once; HMR is creating the registry once but the metrics more than once. |
One thing we could have is like a Or just make that the default in the constructor |
I have a similar problem: a test framework that bypasses Node's module-caching in some cases, so I have to wrap prom-client with my own module that creates meters idempotently. Is this something that would be considered if I wrote it as a PR? I was thinking just what @SimenB describes (I'd have called it |
We just ran into this too, is there a preferred way to ensure counters and other metrics are only created once? |
I don't know if it is the same problem as you but I got this error when I run the tests:
and the script to run tests in package.json:
I modify the
Then the error was fixed. I hope that it will help you if you faced the same problem with test. |
I call |
This works (you have to call clear on every HMR reload on SSR): import promBundle from 'express-prom-bundle'
import prom from 'prom-client'
import { RequestHandler } from 'express'
const applyPrometheusMiddleware = (): RequestHandler => {
prom.register.clear() // to avoid breaking SSR HMR
return promBundle({ includeMethod: true, includePath: true })
}
export default applyPrometheusMiddleware in express initialization: const server = express()
server
.disable('x-powered-by')
.use(applyPrometheusMiddleware()) // don't put this middleware into global variable, or you'll break SSR HMR! |
I'm having the same issue with
client.register.clear() does the job. |
FWIW, we found that |
Hi, I'am using your library and I love it, but I found this little problem (not really a big one, but ...).
I'am using your library in a NestJS project. This framework proposes to use HMR with webpack.
I have a provider class for prometheus-things which have this contructor :
When I'am running my project in my develop environment, and when I modify something somewhere in the project I have this error :
When the Hot Module Reload event is handled, webpack regenerate the changing code but existing metrics are still there.
I have found a workarround :
I call
register.clear()
in my constructor and it works in HMR mode. But I don't like this solution because this line is only here for my comfort allowing me to use HMR in my development phase. It has no direct buisness intrest.So, do you have a better workarround for this problem?
Thank you
The text was updated successfully, but these errors were encountered: