jochen-schweizer / express-prom-bundle

express middleware with standard prometheus metrics in one bundle
MIT License
303 stars 67 forks source link

Add a generalized_status_code (2XX, 3XX, ..) #117

Closed vHanda closed 1 year ago

vHanda commented 1 year ago

It is disabled by default. This way, one has the option of storing both the actual status_code and the generalized one.

Before this commit one could provide a custom function to convert the status_code but that would result in the original status_code being lost.

disjunction commented 1 year ago

Thanks for the effort, but I don't really see the point of having this very specific behavior. In my opinion you can achieve the same result with customLabels and transformLabels.

Here you can see an example of adding a custom label (year): https://github.com/jochen-schweizer/express-prom-bundle/blob/master/advanced-example.js#L13

vHanda commented 1 year ago

Ah. Thanks.

I didn't notice the customLabels. This was so much easier than I thought -

    customLabels: { generalized_status: null },
    transformLabels: (labels) => {
      Object.assign(labels, {
        generalized_status: generalizeStatusCode(labels.status_code),
      });
    },