Comparing version 5.0.1 to 5.1.0
CHANGELOG | ||
========= | ||
## 5.1.0 (2018-2-14) | ||
* @lautis Pass key-value tags as objects | ||
## 5.0.1 (2018-2-2) | ||
@@ -5,0 +8,0 @@ * @punya-asapp Add childClient to TypeScript types |
@@ -55,3 +55,3 @@ "use strict"; | ||
this.mock = options.mock; | ||
this.globalTags = Array.isArray(options.globalTags) ? options.globalTags : []; | ||
this.globalTags = typeof options.globalTags === "object" ? formatTags(options.globalTags, options.telegraf) : []; | ||
this.telegraf = options.telegraf || false; | ||
@@ -223,4 +223,4 @@ this.maxBufferSize = options.maxBufferSize || 0; | ||
var mergedTags = this.globalTags; | ||
if (tags && Array.isArray(tags)) { | ||
mergedTags = overrideTags(mergedTags, tags); | ||
if (tags && typeof(tags) === "object") { | ||
mergedTags = overrideTags(mergedTags, tags, this.telegraf); | ||
} | ||
@@ -340,3 +340,3 @@ if (mergedTags.length > 0) { | ||
if(tags && !Array.isArray(tags)){ | ||
if(tags && typeof tags !== "object"){ | ||
callback = tags; | ||
@@ -416,4 +416,4 @@ tags = undefined; | ||
var mergedTags = this.globalTags; | ||
if(tags && Array.isArray(tags)){ | ||
mergedTags = overrideTags(mergedTags, tags); | ||
if(tags && typeof tags === "object"){ | ||
mergedTags = overrideTags(mergedTags, tags, this.telegraf); | ||
} | ||
@@ -583,4 +583,4 @@ if(mergedTags.length > 0){ | ||
// Append child's tags to parent's tags | ||
globalTags : Array.isArray(options.globalTags) ? | ||
overrideTags(parent.globalTags, options.globalTags) : parent.globalTags, | ||
globalTags : typeof options.globalTags === "object" ? | ||
overrideTags(parent.globalTags, options.globalTags, parent.telegraf) : parent.globalTags, | ||
maxBufferSize : parent.maxBufferSize, | ||
@@ -604,2 +604,19 @@ bufferFlushInterval: parent.bufferFlushInterval, | ||
function sanitizeTags(value, telegraf) { | ||
var blacklist = telegraf ? /:|\|/g : /:|\||@|,/g; | ||
// Replace reserved chars with underscores. | ||
return (value + "").replace(blacklist, "_"); | ||
} | ||
function formatTags(tags, telegraf) { | ||
if (Array.isArray(tags)) { | ||
return tags; | ||
} else { | ||
return Object.keys(tags).map(function (key) { | ||
return sanitizeTags(key, telegraf) + ":" + sanitizeTags(tags[key], telegraf); | ||
}); | ||
} | ||
} | ||
/** | ||
@@ -609,6 +626,6 @@ * Overrides tags in parent with tags from child with the same name (case sensitive) and return the result as new | ||
*/ | ||
function overrideTags (parent, child) { | ||
function overrideTags (parent, child, telegraf) { | ||
var childCopy = {}; | ||
var toAppend = []; | ||
child.forEach(function (tag) { | ||
formatTags(child, telegraf).forEach(function (tag) { | ||
var idx = typeof tag === 'string' ? tag.indexOf(':') : -1; | ||
@@ -615,0 +632,0 @@ if (idx < 1) { // Not found or first character |
{ | ||
"name": "hot-shots", | ||
"description": "Node.js client for StatsD, DogStatsD, and Telegraf", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"author": "Steve Ivy", | ||
@@ -6,0 +6,0 @@ "types": "./types.d.ts", |
@@ -17,6 +17,4 @@ # hot-shots | ||
You generally just need to do one thing: | ||
You should only need to do one thing: change node-statsd to hot-shots in all requires. | ||
1. Change node-statsd to hot-shots in all requires | ||
You may also want to use the Datadog events support in here instead of other libraries. You can also check the detailed [change log](https://github.com/brightcove/hot-shots/blob/master/CHANGES.md) for what has changed since the last release of node-statsd. | ||
@@ -36,3 +34,3 @@ | ||
* `mock`: Create a mock StatsD instance, sending no stats to the server? `default: false` | ||
* `globalTags`: Tags that will be added to every metric `default: []` | ||
* `globalTags`: Tags that will be added to every metric. Can be either an object or list of tags. `default: {}` | ||
* `maxBufferSize`: If larger than 0, metrics will be buffered and only sent when the string length is greater than the size. `default: 0` | ||
@@ -48,3 +46,3 @@ * `bufferFlushInterval`: If buffering is in use, this is the time in ms to always flush any buffered metrics. `default: 1000` | ||
* `sampleRate`: Sends only a sample of data to StatsD `default: 1` | ||
* `tags`: The Array of tags to add to metrics `default: []` | ||
* `tags`: The tags to add to metrics. Can be either an object `{ tag: "value"}` or an array of tags. `default: []` | ||
* `callback`: The callback to execute once the metric has been sent or buffered | ||
@@ -69,3 +67,3 @@ | ||
* `alert_type` Can be ‘error’, ‘warning’, ‘info’ or ‘success’ `default: info` | ||
* `tags`: The Array of tags to add to metrics `default: []` | ||
* `tags`: The tags to add to metrics. Can be either an object `{ tag: "value"}` or an array of tags. `default: []` | ||
* `callback`: The callback to execute once the metric has been sent. | ||
@@ -81,3 +79,3 @@ | ||
* `message` Assign a message to the check. | ||
* `tags`: The Array of tags to add to metrics `default: []` | ||
* `tags`: The tags to add to metrics. Can be either an object `{ tag: "value"}` or an array of tags. `default: []` | ||
* `callback`: The callback to execute once the metric has been sent. | ||
@@ -142,8 +140,9 @@ | ||
client.histogram('my_histogram', 42, 0.25); // 25% Sample Rate | ||
client.histogram('my_histogram', 42, ['tag']); // User-defined tag | ||
client.histogram('my_histogram', 42, { tag: 'value'}]); // User-defined tag | ||
client.histogram('my_histogram', 42, ['tag:value']); // Tags as an array | ||
client.histogram('my_histogram', 42, next); // Callback | ||
client.histogram('my_histogram', 42, 0.25, ['tag']); | ||
client.histogram('my_histogram', 42, 0.25, next); | ||
client.histogram('my_histogram', 42, ['tag'], next); | ||
client.histogram('my_histogram', 42, 0.25, ['tag'], next); | ||
client.histogram('my_histogram', 42, { tag: 'value'}, next); | ||
client.histogram('my_histogram', 42, 0.25, { tag: 'value'}, next); | ||
@@ -155,3 +154,3 @@ // Use a child client to add more context to the client. | ||
suffix: '.additionalSuffix', | ||
globalTags: ['globalTag1:forAllMetricsFromChildClient'] | ||
globalTags: { globalTag1: 'forAllMetricsFromChildClient'} | ||
}); | ||
@@ -171,3 +170,3 @@ childClient.increment('my_counter_with_more_tags'); | ||
* globalTags parameter- DogStatsD or Telegraf | ||
* tags parameter- DogStatsD or Telegraf | ||
* tags parameter- DogStatsD or Telegraf. | ||
* telegraf parameter- Telegraf | ||
@@ -210,3 +209,4 @@ * histogram method- DogStatsD or Telegraf | ||
4. Update README.md with any needed documentation | ||
5. Push your changes and create the PR | ||
5. If you have made any API changes, update types.d.ts | ||
6. Push your changes and create the PR | ||
@@ -213,0 +213,0 @@ When you've done all this we're happy to try to get this merged in right away. |
import dgram = require("dgram"); | ||
declare module "hot-shots" { | ||
export type Tags = { [key: string]: string } | string[]; | ||
export interface ClientOptions { | ||
@@ -9,3 +10,3 @@ bufferFlushInterval?: number; | ||
errorHandler?: (err: Error) => void; | ||
globalTags?: string[]; | ||
globalTags?: Tags; | ||
globalize?: boolean; | ||
@@ -23,5 +24,5 @@ host?: string; | ||
} | ||
export interface ChildClientOptions { | ||
globalTags?: string[]; | ||
globalTags?: Tags; | ||
prefix?: string; | ||
@@ -64,3 +65,3 @@ suffix?: string; | ||
export type StatsCb = (error: Error | undefined, bytes: any) => void; | ||
export type StatsCall = (stat: string | string[], value: number, sampleRate?: number, tags?: string[], callback?: StatsCb) => void; | ||
export type StatsCall = (stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb) => void; | ||
@@ -70,19 +71,19 @@ export class StatsD { | ||
childClient(options?: ChildClientOptions): StatsD; | ||
increment(stat: string): void; | ||
increment(stat: string | string[], value: number, sampleRate?: number, tags?: string[], callback?: StatsCb): void; | ||
increment(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void; | ||
decrement(stat: string): void; | ||
decrement(stat: string | string[], value: number, sampleRate?: number, tags?: string[], callback?: StatsCb): void; | ||
decrement(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void; | ||
timing(stat: string | string[], value: number, sampleRate?: number, tags?: string[], callback?: StatsCb): void; | ||
histogram(stat: string | string[], value: number, sampleRate?: number, tags?: string[], callback?: StatsCb): void; | ||
gauge(stat: string | string[], value: number, sampleRate?: number, tags?: string[], callback?: StatsCb): void; | ||
set(stat: string | string[], value: number, sampleRate?: number, tags?: string[], callback?: StatsCb): void; | ||
unique(stat: string | string[], value: number, sampleRate?: number, tags?: string[], callback?: StatsCb): void; | ||
timing(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void; | ||
histogram(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void; | ||
gauge(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void; | ||
set(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void; | ||
unique(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void; | ||
close(callback: () => void): void; | ||
event(title: string, text?: string, options?: EventOptions, tags?: string[], callback?: StatsCb): void; | ||
check(name: string, status: DatadogChecksValues, options?: CheckOptions, tags?: string[], callback?: StatsCb): void; | ||
event(title: string, text?: string, options?: EventOptions, tags?: Tags, callback?: StatsCb): void; | ||
check(name: string, status: DatadogChecksValues, options?: CheckOptions, tags?: Tags, callback?: StatsCb): void; | ||
@@ -89,0 +90,0 @@ public CHECKS: DatadogChecks; |
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
42985
677