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

Commit 606c4ad

Browse files
committed
introduce statuscodes
1 parent a885b9a commit 606c4ad

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ All options are optional.
2020
* `path` *boolean* include path tag. `default = true`
2121
* `method` *boolean* include http method tag. `default = false`
2222
* `protocol` *boolean* include protocol tag. `default = false`
23+
* `statusCode` *boolean* include status codes. `default = false`
2324

2425
## License
2526

lib/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = function (options) {
44
var datadog = options.dogstatsd || new DD();
55
var stat = options.stat || "node.express.router";
66
var tags = options.tags || [];
7+
var statusCode = options.statusCode || false;
78

89
return function (req, res, next) {
910
if (!req._startTime) {
@@ -27,6 +28,7 @@ module.exports = function (options) {
2728
statTags.push("method:" + req.method.toLowerCase());
2829
}
2930

31+
3032
if (options.protocol && req.protocol) {
3133
statTags.push("protocol:" + req.protocol);
3234
}
@@ -35,7 +37,12 @@ module.exports = function (options) {
3537
statTags.push("path:" + req.path);
3638
}
3739

38-
datadog.histogram(stat, (new Date() - req._startTime), 1, statTags);
40+
if (statuscode) {
41+
statTags.push("status_code:" + req.statusCode);
42+
datadog.increment(stat + '.status_code.' + req.statusCode , 1, statTags);
43+
}
44+
45+
datadog.histogram(stat + '.response_time', (new Date() - req._startTime), 1, statTags);
3946
};
4047

4148
next();

0 commit comments

Comments
 (0)