Comparing version 7.6.0 to 7.7.0
CHANGELOG | ||
========= | ||
## 7.7.0 (2020-7-29) | ||
* @tebriel Add asyncDistTimer function | ||
## 7.6.0 (2020-6-16) | ||
@@ -5,0 +8,0 @@ * @Impeekay Add date type to timing function |
@@ -58,3 +58,3 @@ const helpers = require('./helpers'); | ||
* | ||
* This version of `timer` will record the time take for the asyncronus action returned by `func` | ||
* This version of `timer` will record the time take for the asynchronous action returned by `func` | ||
* not just the execution time of `func` itself. | ||
@@ -80,2 +80,25 @@ * | ||
/** | ||
* Decorates an async function with timing recording behaviour, reported as a distribution. | ||
* | ||
* This version of `timer` will record the time take for the asynchronous action returned by `func` | ||
* not just the execution time of `func` itself. | ||
* | ||
* @param func {<T,A>(...A):Promise<T>} The function to run | ||
* @param stat {String|Array} The stat(s) to send | ||
* @param sampleRate {Number=} The Number of times to sample (0 to 1). Optional. | ||
* @param tags {Array=} The Array of tags to add to metrics. Optional. | ||
* @param callback {Function=} Callback when message is done being delivered. Optional. | ||
*/ | ||
Client.prototype.asyncDistTimer = function (func, stat, sampleRate, tags, callback) { | ||
const self = this; | ||
return (...args) => { | ||
const end = hrtimer(); | ||
const p = func(...args); | ||
const recordStat = () => self.distribution(stat, end(), sampleRate, tags, callback); | ||
p.then(recordStat, recordStat); | ||
return p; | ||
}; | ||
}; | ||
/** | ||
* High-resolution timer | ||
@@ -82,0 +105,0 @@ */ |
{ | ||
"name": "hot-shots", | ||
"description": "Node.js client for StatsD, DogStatsD, and Telegraf", | ||
"version": "7.6.0", | ||
"version": "7.7.0", | ||
"author": "Steve Ivy", | ||
@@ -6,0 +6,0 @@ "types": "./types.d.ts", |
@@ -16,2 +16,3 @@ # hot-shots | ||
* asyncTimer | ||
* asyncDistTimer | ||
* much more, including many bug fixes | ||
@@ -174,3 +175,3 @@ | ||
// Async timer: Similar to timer above, but you instead pass in a funtion | ||
// Async timer: Similar to timer above, but you instead pass in a function | ||
// that returns a Promise. And then it returns a Promise that will record the timing. | ||
@@ -183,2 +184,9 @@ var fn = function () { return new Promise(function (resolve, reject) { setTimeout(resolve, n); }); }; | ||
// Async timer: Similar to asyncTimer above, but it instead emits a distribution. | ||
var fn = function () { return new Promise(function (resolve, reject) { setTimeout(resolve, n); }); }; | ||
var instrumented = statsd.asyncDistTimer(fn, 'fn_execution_time'); | ||
instrumented().then(function() { | ||
console.log('Code run and metric sent'); | ||
}); | ||
// Sampling, tags and callback are optional and could be used in any combination (DataDog and Telegraf only) | ||
@@ -185,0 +193,0 @@ client.histogram('my_histogram', 42, 0.25); // 25% Sample Rate |
@@ -103,2 +103,7 @@ import dgram = require("dgram"); | ||
asyncDistTimer<P extends any[], R>(func: (...args: P) => Promise<R>, stat: string | string[], sampleRate?: number, tags?: Tags, callback?: StatsCb): (...args: P) => Promise<R>; | ||
asyncDistTimer<P extends any[], R>(func: (...args: P) => Promise<R>, stat: string | string[], tags?: Tags, callback?: StatsCb): (...args: P) => Promise<R>; | ||
asyncDistTimer<P extends any[], R>(func: (...args: P) => Promise<R>, stat: string | string[], callback?: StatsCb): (...args: P) => Promise<R>; | ||
asyncDistTimer<P extends any[], R>(func: (...args: P) => Promise<R>, stat: string | string[], sampleRate?: number, callback?: StatsCb): (...args: P) => Promise<R>; | ||
histogram(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void; | ||
@@ -105,0 +110,0 @@ histogram(stat: string | string[], value: number, tags?: Tags, callback?: StatsCb): void; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78920
1463
291