express-statsd icon indicating copy to clipboard operation
express-statsd copied to clipboard

Add sane default behavior for missing statsdKey

Open tomuber opened this issue 11 years ago • 9 comments

cc @Raynos @kumikoda @mlmorg

Updated based on Jake's feedback: -Don't provide a middleware -I opted to provide a sane default for when the user does not provide a statsdKey

tomuber avatar Aug 29 '14 19:08 tomuber

If we are going to pave a cowpath we should probably do a little better then this.

We can change the express-statsd module to be

var statsd = require('express-statsd');
var computeKey = require('express-statsd/compute-key');

statsd(req, res, {
  statsdKey: computeKey(req, res)
}, cb)

We can put the code you have for computing the key value in a compute-key function.

We can then get rid of the middleware stuff.

Raynos avatar Aug 29 '14 19:08 Raynos

+1 on what jake said. No middleware stuff!

kumikoda avatar Aug 29 '14 19:08 kumikoda

@Raynos @mlmorg @kumikoda I updated this based on jake's feedback, I opted to provide a sane default for when the user doesn't provide a statsdKey

tomuber avatar Aug 30 '14 08:08 tomuber

This is failing on lynx not being available for node 0.8

tomuber avatar Aug 30 '14 08:08 tomuber

I think this should be two libraries: http-statsd and express-statsd. http-statsd can follow @Raynos' interface while express-statsd can build upon it and allow you to do something like:

server.get('/', 'root.statsd-key', function (req, res) {...});

Also, let me mention my dislike for trying to provide a "sane" default for three reasons:

  1. With this approach, you'd now be logging any pathname + query param that a user decides to hit, regardless of whether it's an actual route that the service supports or not, e.g. /mistyped-route?foo=bar
  2. You'd log all permutations of routes like /users/:id separately.
  3. You may eventually run into collisions, e.g. /foo/bar and /foo_bar

We may be able to provide some ok defaults based on express' req.route interface but, again, it will never be perfect (e.g. * wildcards and collisions like issue 3 above) and that's why I would rather the eng just have to set it themselves.

mlmorg avatar Aug 30 '14 13:08 mlmorg

@mlmorg you are correct.

What you really want is integration with a routing table -.-

statsd(req, res, {
  routePattern: x
})

Which should work fine.

@mlmorg

  • wildcards and collisions like issue 3 above

can we not just find a way of encoding a route pattern without running into collisions?

Raynos avatar Aug 30 '14 16:08 Raynos

The default is only for the top level URI, so # 2/3 won't apply. Re: # 1 it'll log the pathname and not the query params.

tomuber avatar Sep 02 '14 19:09 tomuber

What's the point of only logging the content within the first /'s?

mlmorg avatar Sep 10 '14 17:09 mlmorg

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Jun 27 '19 13:06 CLAassistant