Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Issue while passing express app in the options #35

Open
iravishah opened this issue Jul 9, 2020 · 3 comments
Open

Issue while passing express app in the options #35

iravishah opened this issue Jul 9, 2020 · 3 comments

Comments

@iravishah
Copy link

this.request.proto = parent.request;
^

TypeError: Cyclic proto value
at IncomingMessage.set proto [as proto] ()

@joao-fontenele
Copy link
Owner

hello, please provide more details of how the error occurred, a minimal snippet of code, that reproduces the error would be very heplful

@iravishah
Copy link
Author

`const express = require('express');
const httpCollector = require('express-prometheus-middleware');
const app = express();

const PORT = 9091;

app.use(httpCollector({
metricsPath: '/metrics',
collectDefaultMetrics: false,
collectGCMetrics: false,
metricsApp: app,
// requestDurationBuckets: [0.1, 0.5, 1, 1.5],
/**

  • Uncomenting the authenticate callback will make the metricsPath route
  • require authentication. This authentication callback can make a simple
  • basic auth test, or even query a remote server to validate access.
  • To access /metrics you could do:
  • curl -X GET user:password@localhost:9091/metrics
    /
    // authenticate: req => req.headers.authorization === 'Basic dXNlcjpwYXNzd29yZA==',
    /
    *
  • Uncommenting the extraMasks config will use the list of regexes to
  • reformat URL path names and replace the values found with a placeholder value
    /
    // extraMasks: [/..:..:..:..:..:../],
    /
    *
  • The prefix option will cause all metrics to have the given prefix.
  • E.g.: app_prefix_http_requests_total
    /
    // prefix: 'test_',
    /
    *
  • Can add custom labels with customLabels and transformLabels options
    */
    customLabels: ['contentType', 'statusCode'],
    transformLabels(labels, req, res) {
    // // eslint-disable-next-line no-param-reassign
    labels.contentType = req.headers['content-type'];
    labels.statusCode = res.statusCode;
    },
    }));

app.get('/test', (req, res, next) => {
res.status(400).send('ok')
});

app.listen(PORT, () => console.log(Example app listening on port ${PORT}!));`

Here in the snippet, I have used the main application's express app instance metricsApp: app.

@joao-fontenele
Copy link
Owner

joao-fontenele commented Jul 12, 2020

Hello, this is an interesting case.

If you plan to use the same port and express app to respond the /metrics route, you don't need to pass an express instance. So a quick fix is just to not pass the metricsApp argument to the lib. To fix, I will likely have to document this behavior, or will find a way to check this specific case

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

No branches or pull requests

2 participants