Comparing version 7.5.0 to 7.6.0
CHANGELOG | ||
========= | ||
## 7.6.0 (2020-6-16) | ||
* @Impeekay Add date type to timing function | ||
## 7.5.0 (2020-6-5) | ||
@@ -5,0 +8,0 @@ * @benblack86 Unreference underlying socket/interval to prevent process hangs |
@@ -12,3 +12,3 @@ const helpers = require('./helpers'); | ||
* @param stat {String|Array} The stat(s) to send | ||
* @param time {Number} The time in milliseconds to send | ||
* @param time {Number|Date} The time in milliseconds to send or Date object of which the difference is calculated | ||
* @param sampleRate {Number=} The Number of times to sample (0 to 1). Optional. | ||
@@ -19,3 +19,4 @@ * @param tags {Array=} The Array of tags to add to metrics. Optional. | ||
Client.prototype.timing = function (stat, time, sampleRate, tags, callback) { | ||
this.sendAll(stat, time, 'ms', sampleRate, tags, callback); | ||
const t = time instanceof Date ? new Date() - time : time; | ||
this.sendAll(stat, t, 'ms', sampleRate, tags, callback); | ||
}; | ||
@@ -22,0 +23,0 @@ |
{ | ||
"name": "hot-shots", | ||
"description": "Node.js client for StatsD, DogStatsD, and Telegraf", | ||
"version": "7.5.0", | ||
"version": "7.6.0", | ||
"author": "Steve Ivy", | ||
@@ -6,0 +6,0 @@ "types": "./types.d.ts", |
@@ -109,21 +109,2 @@ # hot-shots | ||
// Timing: sends a timing command with the specified milliseconds | ||
client.timing('response_time', 42); | ||
// Timer: Returns a function that you call to record how long the first | ||
// parameter takes to execute (in milliseconds) and then sends that value | ||
// using 'client.timing'. | ||
// The parameters after the first one (in this case 'fn') | ||
// match those in 'client.timing'. | ||
var fn = function(a, b) { return a + b }; | ||
client.timer(fn, 'fn_execution_time')(2, 2); | ||
// Async timer: Similar to timer above, but you instead pass in a funtion | ||
// that returns a Promise. And then it returns a Promise that will record the timing. | ||
var fn = function () { return new Promise(function (resolve, reject) { setTimeout(resolve, n); }); }; | ||
var instrumented = statsd.asyncTimer(fn, 'fn_execution_time'); | ||
instrumented().then(function() { | ||
console.log('Code run and metric sent'); | ||
}); | ||
// Increment: Increments a stat by a value (default is 1) | ||
@@ -177,2 +158,24 @@ client.increment('my_counter'); | ||
} | ||
}); | ||
// Timing: sends a timing command with the specified milliseconds | ||
client.timing('response_time', 42); | ||
// Timing: also accepts a Date object of which the difference is calculated | ||
client.timing('response_time', new Date()); | ||
// Timer: Returns a function that you call to record how long the first | ||
// parameter takes to execute (in milliseconds) and then sends that value | ||
// using 'client.timing'. | ||
// The parameters after the first one (in this case 'fn') | ||
// match those in 'client.timing'. | ||
var fn = function(a, b) { return a + b }; | ||
client.timer(fn, 'fn_execution_time')(2, 2); | ||
// Async timer: Similar to timer above, but you instead pass in a funtion | ||
// that returns a Promise. And then it returns a Promise that will record the timing. | ||
var fn = function () { return new Promise(function (resolve, reject) { setTimeout(resolve, n); }); }; | ||
var instrumented = statsd.asyncTimer(fn, 'fn_execution_time'); | ||
instrumented().then(function() { | ||
console.log('Code run and metric sent'); | ||
}); | ||
@@ -179,0 +182,0 @@ |
@@ -57,3 +57,3 @@ import dgram = require("dgram"); | ||
K4 extends keyof T, | ||
> = T[K1] | T[K2] | T[K3] | T[K4]; | ||
> = T[K1] | T[K2] | T[K3] | T[K4]; | ||
@@ -89,6 +89,6 @@ export type DatadogChecksValues = unionFromInterfaceValues4<DatadogChecks, "OK", "WARNING", "CRITICAL", "UNKNOWN">; | ||
timing(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void; | ||
timing(stat: string | string[], value: number, tags?: Tags, callback?: StatsCb): void; | ||
timing(stat: string | string[], value: number, callback?: StatsCb): void; | ||
timing(stat: string | string[], value: number, sampleRate?: number, callback?: StatsCb): void; | ||
timing(stat: string | string[], value: number | Date, sampleRate?: number, tags?: Tags, callback?: StatsCb): void; | ||
timing(stat: string | string[], value: number | Date, tags?: Tags, callback?: StatsCb): void; | ||
timing(stat: string | string[], value: number | Date, callback?: StatsCb): void; | ||
timing(stat: string | string[], value: number | Date, sampleRate?: number, callback?: StatsCb): void; | ||
@@ -95,0 +95,0 @@ timer<P extends any[], R>(func: (...args: P) => R, stat: string | string[], sampleRate?: number, tags?: Tags, callback?: StatsCb): (...args: P) => R; |
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
76854
1437
283