@bbc/http-transport-statsd
Advanced tools
Comparing version
@@ -12,19 +12,19 @@ 'use strict'; | ||
module.exports = (stats, statsName, feedName) => { | ||
return (ctx, next) => { | ||
return next() | ||
.catch((err) => { | ||
stats.increment(`${createStatsName(statsName, feedName)}.request_errors`); | ||
stats.timing(`${createStatsName(statsName, feedName)}.attempts`, ctx.res.retries.length + 1); | ||
throw err; | ||
}) | ||
.then(() => { | ||
stats.increment(`${createStatsName(statsName, feedName)}.requests`); | ||
stats.increment(`${createStatsName(statsName, feedName)}.responses.${ctx.res.statusCode}`); | ||
stats.timing(`${createStatsName(statsName, feedName)}.response_time`, ctx.res.elapsedTime); | ||
stats.timing(`${createStatsName(statsName, feedName)}.attempts`, ctx.res.retries.length + 1); | ||
ctx.res.retries.forEach(() => { | ||
return stats.increment(`${createStatsName(statsName, feedName)}.retries`); | ||
}); | ||
}); | ||
return async (ctx, next) => { | ||
try { | ||
await next(); | ||
} catch (err) { | ||
stats.increment(`${createStatsName(statsName, feedName)}.request_errors`); | ||
stats.timing(`${createStatsName(statsName, feedName)}.attempts`, ctx.retryAttempts.length + 1); | ||
throw err; | ||
} | ||
stats.increment(`${createStatsName(statsName, feedName)}.requests`); | ||
stats.increment(`${createStatsName(statsName, feedName)}.responses.${ctx.res.statusCode}`); | ||
stats.timing(`${createStatsName(statsName, feedName)}.response_time`, ctx.res.elapsedTime); | ||
stats.timing(`${createStatsName(statsName, feedName)}.attempts`, ctx.retryAttempts.length + 1); | ||
ctx.retryAttempts.forEach(() => { | ||
return stats.increment(`${createStatsName(statsName, feedName)}.retries`); | ||
}); | ||
}; | ||
}; |
{ | ||
"name": "@bbc/http-transport-statsd", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Provides stats for statsD ", | ||
@@ -20,3 +20,3 @@ "main": "index.js", | ||
"engines": { | ||
"node": ">=4.0.0" | ||
"node": ">=8.0.0" | ||
}, | ||
@@ -34,6 +34,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"@bbc/http-transport": "0.0.1", | ||
"@bbc/http-transport": "^3.0.0", | ||
"chai": "^4.1.2", | ||
"eslint": "^2.4.0", | ||
"eslint-config-iplayer-es6": "^1.3.0", | ||
"eslint": "^4.11.0", | ||
"eslint-config-iplayer-es6": "^3.1.1", | ||
"istanbul": "^0.4.1", | ||
@@ -46,4 +46,7 @@ "lodash": "^4.17.4", | ||
"eslintConfig": { | ||
"extends": "iplayer-es6" | ||
"extends": "iplayer-es6", | ||
"parserOptions": { | ||
"ecmaVersion": 2017 | ||
} | ||
} | ||
} |
@@ -1,3 +0,1 @@ | ||
[](https://travis-ci.org/bbc/http-transport-statsd) [](https://coveralls.io/github/bbc/http-transport-statsd?branch=master) | ||
# http-transport-statsd | ||
@@ -21,3 +19,3 @@ | ||
``` | ||
npm install --save http-transport-statsd | ||
npm install --save @bbc/http-transport-statsd | ||
``` | ||
@@ -30,4 +28,4 @@ | ||
const url = 'http://example.com/'; | ||
const HttpTransport = require('http-transport'); | ||
const sendStats = require('http-transport-statsd'); | ||
const HttpTransport = require('@bbc/http-transport'); | ||
const sendStats = require('@bbc/http-transport-statsd'); | ||
const StatsD = require('node-statsd'); | ||
@@ -37,3 +35,3 @@ const statsD = new StatsD(); | ||
HttpTransport.createClient() | ||
.useGlobal(sendStats(statsd)) | ||
.use(sendStats(statsd)) // send stats for this request | ||
.get(url) | ||
@@ -40,0 +38,0 @@ .asBody() |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
9202
71.68%11
22.22%149
413.79%52
-3.7%1
Infinity%