Skip to content
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

metrics can be attached to specific endpoint programatically, but will raise TS2339 #44

Open
arnaudruffin opened this issue Aug 7, 2019 · 3 comments

Comments

@arnaudruffin
Copy link

Hi

I am attaching metrics programatically in TypeScript. This used to work fine with a previous version (5.0.2) but with recent updates I now have a TypeScript error:
error TS2339: Property 'metricsMiddleware' does not exist on type 'RequestHandler'.

Here is how I used to do it in 5.0.2:

import expressPromBundle from "express-prom-bundle";
const PROMETHEUS_BUNDLE = expressPromBundle({...})
[...]
expressApp.route("/metrics").get(function (req, res) {
            PROMETHEUS_BUNDLE.metricsMiddleware(req, res);
        });

Here is how I try to do it now (with the error TS2339):

expressApp.use("/metrics", PROMETHEUS_BUNDLE_METRICS_MIDDLEWARE.metricsMiddleware);

This is only a typing issue and does not prevent my server from running correctly.

@poteirard
Copy link

I have the same problem. I think this line is wrong:

// /types/index.d.ts
declare function express_prom_bundle(opts: express_prom_bundle.Opts): RequestHandler;

It should be something like:

declare function express_prom_bundle(opts: express_prom_bundle.Opts):
{ 
	metrics: ...
	metricsMiddleware: RequestHandler,
	promClient: ...
}

Maybe @raszi can put a bit of light on this? I would be happy to help with a PR

@raszi
Copy link
Contributor

raszi commented Nov 25, 2019

That is not the correct way to use the library AFAIK:

import * as promBundle from 'express-prom-bundle'
const metricsMiddleware = promBundle({...});

expressApp.route("/metrics").get(function (req, res) {
  return metricsMiddleware(req, res);
});

Or more simply as the documentation says:

import * as promBundle from 'express-prom-bundle'
const metricsMiddleware = promBundle({...});

expressApp.use(metricsMiddleware);

@raszi
Copy link
Contributor

raszi commented Nov 25, 2019

The type tests might also help you here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants