Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

statsd-client

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

statsd-client - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

37

lib/helpers/getExpressMiddleware.js
/*
* Return express middleware that measures overall performance.
*
* The `prefix` defaults to `''` (but is currently mandatory). The
* `options`-argument is optional.
* * You can set `timeByUrl`, that add a timer per URL template (ex:
* `/api/:username/:thingie`). This can be changed run-time by setting
* `res.locals.statsdUrlKey`.
* * Add a `function(client, startTime, req, res)` in `onResponseEnd` that
* will be called at the very end.
*/

@@ -19,14 +27,25 @@ function factory(parentClient) {

client.timing('response_time', startTime);
client.increment('response.' + res.statusCode);
if (timeByUrl && req.route && req.route.path) {
var routeName = req.route.path;
if (Object.prototype.toString.call(routeName) === '[object RegExp]') {
// Might want to do some sanitation here?
routeName = routeName.source;
var routeName;
// Did we get a harc-coded name, or should we figure one out?
if (res.locals && res.locals.statsdUrlKey) {
routeName = res.locals.statsdUrlKey;
} else {
routeName = req.route.path;
if (Object.prototype.toString.call(routeName) === '[object RegExp]') {
// Might want to do some sanitation here?
routeName = routeName.source;
}
if (routeName === "/") routeName = "root";
routeName = req.method + '_' + routeName;
}
if (routeName === "/") routeName = "root";
// need to get rid of : in route names, remove first /, and replace rest with _
routeName = req.method + '_' + routeName.replace(/:/g, "").replace(/\//, "").replace(/\//g, "_");
client.timing('response_time.by_url.' + routeName, startTime);
// Get rid of : in route names, remove first /, and replace
// rest with _.
routeName = 'response_time.' + routeName.replace(/:/g, "").replace(/\//, "").replace(/\//g, "_"),
client.timing(routeName, startTime);
} else {
client.timing('response_time', startTime);
}

@@ -33,0 +52,0 @@

@@ -6,3 +6,3 @@ {

"keywords": ["statsd", "client", "metrics", "udp"],
"version": "0.0.10",
"version": "0.0.11",
"homepage": "https://github.com/msiebuhr/node-statsd-client",

@@ -9,0 +9,0 @@ "bugs": "https://github.com/msiebuhr/node-statsd-client/issues",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc