@shopify/statsd
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -8,4 +8,8 @@ # Changelog | ||
## [Unreleased] | ||
## [1.1.0] - 2019-10-08 | ||
### Added | ||
- now handles converting non-string values to strings for tag dictionaries and converts empty tag values to `Unknown` [#1095](https://github.com/Shopify/quilt/pull/1095) | ||
## [1.0.0] - 2019-10-07 | ||
@@ -16,3 +20,1 @@ | ||
- `@shopify/statsd` package | ||
[unreleased]: https://github.com/Shopify/quilt/compare/@shopify/statsd@1.0.0...HEAD |
@@ -1,5 +0,6 @@ | ||
import { ClientOptions, Tags } from 'hot-shots'; | ||
import { ClientOptions } from 'hot-shots'; | ||
export interface Logger { | ||
log(message: string): void; | ||
} | ||
declare type Tags = Record<string, string | number | boolean | null | undefined> | string[]; | ||
export interface Options extends ClientOptions { | ||
@@ -21,1 +22,2 @@ logger?: Logger; | ||
} | ||
export {}; |
@@ -6,2 +6,3 @@ "use strict"; | ||
var change_case_1 = require("change-case"); | ||
var UNKNOWN = 'Unknown'; | ||
var StatsDClient = /** @class */ (function () { | ||
@@ -43,3 +44,3 @@ function StatsDClient(_a) { | ||
this.statsd = this.statsd.childClient({ | ||
globalTags: globalTags, | ||
globalTags: this.normalizeTags(globalTags), | ||
}); | ||
@@ -57,6 +58,28 @@ }; | ||
StatsDClient.prototype.normalizeTags = function (tags) { | ||
if (!this.options.snakeCase) { | ||
if (tags === void 0) { tags = []; } | ||
var e_1, _a; | ||
if (Array.isArray(tags)) { | ||
return tags; | ||
} | ||
return snakeCaseTags(tags); | ||
var output = {}; | ||
try { | ||
for (var _b = tslib_1.__values(Object.entries(tags)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = tslib_1.__read(_c.value, 2), key = _d[0], value = _d[1]; | ||
var newValue = value == null ? UNKNOWN : String(value); | ||
if (this.options.snakeCase) { | ||
output[change_case_1.snakeCase(key)] = newValue; | ||
} | ||
else { | ||
output[key] = newValue; | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return output; | ||
}; | ||
@@ -66,10 +89,1 @@ return StatsDClient; | ||
exports.StatsDClient = StatsDClient; | ||
function snakeCaseTags(tags) { | ||
if (tags == null) { | ||
return tags; | ||
} | ||
return Object.keys(tags).reduce(function (object, tag) { | ||
var _a; | ||
return (tslib_1.__assign({}, object, (_a = {}, _a[change_case_1.snakeCase(tag)] = tags[tag], _a))); | ||
}, {}); | ||
} |
{ | ||
"name": "@shopify/statsd", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "An opinionated StatsD client for Shopify Node.js server and other StatsD utilities.", |
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
6839
112