jochen-schweizer / express-prom-bundle

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

extraMasks not working #39

Closed oreporan closed 5 years ago

oreporan commented 5 years ago

Hey, I can't seem to get the extraMasks of the urlValueParser working, my setup looks like this -

promBundle({ 
   includeMethod: true, 
   includePath: true, 
   buckets: webRequestsBuckets,
   urlValueParser: {
        extraMasks: [
            /^some-email-regex$/,
        ],
    }
})

The regex is not catching, I know this because I'm using the same UrlValueParser library for my logger in a different area of my code -

Works:

const parser = new UrlValueParser({
    extraMasks: [
       /^some-email-regex$/,
    ],
});
....
parser.replacePathValues(req.originalUrl, '#val')

any ideas why? I saw from your code that the options are being passed, so I can't figure out the issue...

Also, in your includePath example you omit the includePath : true

oreporan commented 5 years ago

Was an internal issue, closing

oreporan commented 5 years ago

Turns out the problem was that my regex: /^(([^<>()[]\\.,;:s@"]+(.[^<>()[]\\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/

When turned to a string by just converting / to ' was not the same. since urlValueParser allows Regex, I think in the typescript definition you should allow (string|RegExp)[]

disjunction commented 5 years ago

good point. Will fix together with the docs. Thanks!

oreporan commented 5 years ago

Also - any chance to get an example of transformLabels ? :)

disjunction commented 5 years ago

it here: https://github.com/jochen-schweizer/express-prom-bundle/blob/master/advanced-example.js#L13