diff --git a/README.md b/README.md index 53f5b02..5b857ca 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Which labels to include in `http_request_duration_seconds` metric: * **includeUp**: include an auxiliary "up"-metric which always returns 1, default: **true** * **metricsPath**: replace the `/metrics` route with a **regex** or exact **string**. Note: it is highly recommended to just stick to the default * **metricType**: histogram/summary selection. See more details below - +* **filter**: whether the incoming request should be included in the metrics ### metricType option ### diff --git a/src/index.js b/src/index.js index bf747fc..900f901 100644 --- a/src/index.js +++ b/src/index.js @@ -131,6 +131,10 @@ function main(opts) { : new RegExp('^' + (opts.metricsPath || '/metrics') + '/?$'); const middleware = function (req, res, next) { + if (opts.filter && opts.filter(req)) { + return next(); + } + const path = req.originalUrl || req.url; // originalUrl gets lost in koa-connect? if (opts.autoregister && path.match(metricsMatch)) { diff --git a/types/index.d.ts b/types/index.d.ts index a59dfaa..57469fc 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -28,6 +28,8 @@ declare namespace express_prom_bundle { includePath?: boolean; includeUp?: boolean; + filter?: (req: Request) => boolean; + metricType?: 'summary' | 'histogram'; metricsPath?: string; httpDurationMetricName?: string;