jochen-schweizer / express-prom-bundle

express middleware with standard prometheus metrics in one bundle
MIT License
310 stars 68 forks source link

Improve Typescript definition of bundle output #57

Closed jorge07 closed 4 years ago

jorge07 commented 4 years ago

Problem

With the current implementation Typescript will not compile in the following example as metricsMiddleware is not refined as a property in the main function output.

const metricsRequestMiddleware = prometheus({...config, ...{
  includePath: true,
  includeMethod: true,
  autoregister: false,
  promClient: {
      collectDefaultMetrics: {},
  },
}});
const { metricsMiddleware } = metricsRequestMiddleware

With the current typescript definition there's no access to certain objects that are already defined in the index.js file.

Why is this needed

I'm trying to expose the metrics in a different port (and express app) for conventions in the company and as best practice. This PR allows define the metric for an express and expose the metrics in another one. I.E:

const metricsRequestMiddleware = prometheus({...config, ...{
  includePath: true,
  includeMethod: true,
  autoregister: false,
  promClient: {
      collectDefaultMetrics: {},
  },
}});

http.use(metricsRequestMiddleware);
monitor.use(metricsRequestMiddleware.metricsMiddleware);

const server: Server = await http.listen(port, () => {
  this.logger.info(`🚀 Server is running in http://localhost:${port}`);
});
const monitor: Server = await monitor.listen(9800, () => {
  this.logger.info(`🚀 Monitor is running in http://localhost:9800/metrics`);
});

Thanks

jorge07 commented 4 years ago

Duplicated #56 sorry