Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit b88a288

Browse files
starting point
1 parent 8e5fb50 commit b88a288

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require("./lib");

lib/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var DD = require("node-dogstatsd").StatsD;
2+
3+
module.exports = function (options) {
4+
var datadog = options.dogstatsd || new DD();
5+
var stat = options.stat || "node.express.router";
6+
var tagPrefix = options.tagPrefix || "express";
7+
8+
if (tagPrefix.substr(-1) != ":") {
9+
tagPrefix += ":";
10+
}
11+
12+
return function (req, res, next) {
13+
if (!req._startTime) {
14+
req._startTime = new Date();
15+
}
16+
17+
var end = res.end;
18+
res.end = function (chunk, encoding) {
19+
res.end = end;
20+
res.end(chunk, encoding);
21+
22+
if (!req.route || !req.route.path) {
23+
return;
24+
}
25+
26+
datadog.histogram(stat, (new Date() - req._startTime), 1, [
27+
"express:route:" + req.route.path,
28+
"express:path:" + req.path
29+
]);
30+
};
31+
32+
next();
33+
};
34+
};

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
],
1414
"author": "App Press",
1515
"license": "MIT",
16-
"readmeFilename": "README.md"
16+
"readmeFilename": "README.md",
17+
"dependencies": {
18+
"node-dogstatsd": "0.0.4"
19+
}
1720
}

0 commit comments

Comments
 (0)