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

connect-datadog

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-datadog - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

lib/index.test.js

59

lib/index.js

@@ -1,11 +0,30 @@

var DD = require("node-dogstatsd").StatsD;
const DD = require("node-dogstatsd").StatsD;
module.exports = function (options) {
var datadog = options.dogstatsd || new DD();
var stat = options.stat || "node.express.router";
var tags = options.tags || [];
var path = options.path || false;
var base_url = options.base_url || false;
var response_code = options.response_code || false;
let datadog = options.dogstatsd || new DD();
let stat = options.stat || "node.express.router";
let tags = options.tags || [];
let path = options.path || false;
let base_url = options.base_url || false;
let method = options.method || false;
let protocol = options.protocol || false;
let response_code = options.response_code || false;
let DELIM = options.delim || '-';
let REGEX_PIPE = /\|/g;
/**
* Checks if str is a regular expression and stringifies it if it is.
* Returns a string with all instances of the pipe character replaced with
* the delimiter.
* @param {*} str The string to check for pipe chars
* @return {string} The input string with pipe chars replaced
*/
function replacePipeChar(str) {
if (str instanceof RegExp) {
str = str.toString();
}
return str && str.replace(REGEX_PIPE, DELIM);
}
return function (req, res, next) {

@@ -16,3 +35,3 @@ if (!req._startTime) {

var end = res.end;
let end = res.end;
res.end = function (chunk, encoding) {

@@ -26,26 +45,24 @@ res.end = end;

var baseUrl = (base_url !== false) ? req.baseUrl : '';
var statTags = [
"route:" + baseUrl + req.route.path
].concat(tags);
const baseUrl = (base_url !== false) ? req.baseUrl : '';
let statTags = [`route:${baseUrl + replacePipeChar(req.route.path)}`].concat(tags);
if (options.method) {
statTags.push("method:" + req.method.toLowerCase());
if (method !== false) {
statTags.push(`method:${req.method.toLowerCase()}`);
}
if (options.protocol && req.protocol) {
statTags.push("protocol:" + req.protocol);
if (protocol && req.protocol) {
statTags.push(`protocol:${req.protocol}`);
}
if (path !== false) {
statTags.push("path:" + baseUrl + req.path);
statTags.push(`path:${req.path}`);
}
if (response_code) {
statTags.push("response_code:" + res.statusCode);
datadog.increment(stat + '.response_code.' + res.statusCode , 1, statTags);
datadog.increment(stat + '.response_code.all' , 1, statTags);
statTags.push(`response_code:${res.statusCode}`);
datadog.increment(`${stat}.response_code.${res.statusCode}`, 1, statTags);
datadog.increment(`${stat}.response_code.all`, 1, statTags);
}
datadog.histogram(stat + '.response_time', (new Date() - req._startTime), 1, statTags);
datadog.histogram(`${stat}.response_time`, new Date() - req._startTime, 1, statTags);
};

@@ -52,0 +69,0 @@

{
"name": "connect-datadog",
"version": "0.0.6",
"version": "0.0.7",
"description": "Datadog middleware for Connect JS / Express",

@@ -8,4 +8,7 @@ "main": "index.js",

"type": "git",
"url": "git://github.com/AppPress/node-connect-datadog.git"
"url": "git://github.com/DataDog/node-connect-datadog.git"
},
"scripts": {
"test": "jest"
},
"keywords": [

@@ -15,3 +18,3 @@ "datadog",

],
"author": "App Press",
"author": "Datadog",
"license": "MIT",

@@ -21,3 +24,6 @@ "readmeFilename": "README.md",

"node-dogstatsd": "0.0.6"
},
"devDependencies": {
"jest": "^22.4.2"
}
}

@@ -17,9 +17,11 @@ # node-connect-datadog

* `dogstatsd` node-dogstatsd client. `default = new (require("node-dogstatsd")).StatsD()`
* `dogstatsd` node-dogstatsd client. `default = new require("node-dogstatsd").StatsD()`
* `stat` *string* name for the stat. `default = "node.express.router"`
* `tags` *array* of tags to be added to the histogram. `default = []`
* `path` *boolean* include path tag. `default = false`
* `base_url` *boolean* include baseUrl. `default = false`
* `method` *boolean* include http method tag. `default = false`
* `protocol` *boolean* include protocol tag. `default = false`
* `response_code` *boolean* include http response codes. `default = false`
* `delim` *string* char to replace pipe char with in the route `default = '-'`

@@ -26,0 +28,0 @@ ## License

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