@shopify/statsd
Advanced tools
Comparing version 2.1.3 to 2.1.4
@@ -1,12 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StatsDClient = void 0; | ||
var tslib_1 = require("tslib"); | ||
var hot_shots_1 = require("hot-shots"); | ||
var change_case_1 = require("change-case"); | ||
var UNKNOWN = 'Unknown'; | ||
var StatsDClient = /** @class */ (function () { | ||
function StatsDClient(_a) { | ||
var _this = this; | ||
var logger = _a.logger, options = tslib_1.__rest(_a, ["logger"]); | ||
import { StatsD } from 'hot-shots'; | ||
import { snakeCase } from 'change-case'; | ||
const UNKNOWN = 'Unknown'; | ||
export class StatsDClient { | ||
constructor(_a) { | ||
var { logger } = _a, options = __rest(_a, ["logger"]); | ||
this.logger = console; | ||
@@ -16,83 +11,63 @@ if (logger) { | ||
} | ||
this.options = tslib_1.__assign(tslib_1.__assign({}, options), { errorHandler: options.errorHandler | ||
this.options = Object.assign(Object.assign({}, options), { errorHandler: options.errorHandler | ||
? options.errorHandler | ||
: function (error) { | ||
_this.logger.log("Error occurred in the StatsD client:\n" + (error.stack || error.message)); | ||
: (error) => { | ||
this.logger.log(`Error occurred in the StatsD client:\n${error.stack || error.message}`); | ||
} }); | ||
this.statsd = new hot_shots_1.StatsD(this.options); | ||
this.statsd = new StatsD(this.options); | ||
} | ||
StatsDClient.prototype.distribution = function (stat, value, tags) { | ||
var _this = this; | ||
return new Promise(function (resolve) { | ||
_this.statsd.distribution(stat, value, _this.normalizeTags(tags), _this.createCallback(resolve)); | ||
distribution(stat, value, tags) { | ||
return new Promise(resolve => { | ||
this.statsd.distribution(stat, value, this.normalizeTags(tags), this.createCallback(resolve)); | ||
}); | ||
}; | ||
StatsDClient.prototype.timing = function (stat, value, tags) { | ||
var _this = this; | ||
return new Promise(function (resolve) { | ||
_this.statsd.timing(stat, value, _this.normalizeTags(tags), _this.createCallback(resolve)); | ||
} | ||
timing(stat, value, tags) { | ||
return new Promise(resolve => { | ||
this.statsd.timing(stat, value, this.normalizeTags(tags), this.createCallback(resolve)); | ||
}); | ||
}; | ||
StatsDClient.prototype.gauge = function (stat, value, tags) { | ||
var _this = this; | ||
return new Promise(function (resolve) { | ||
_this.statsd.gauge(stat, value, _this.normalizeTags(tags), _this.createCallback(resolve)); | ||
} | ||
gauge(stat, value, tags) { | ||
return new Promise(resolve => { | ||
this.statsd.gauge(stat, value, this.normalizeTags(tags), this.createCallback(resolve)); | ||
}); | ||
}; | ||
StatsDClient.prototype.increment = function (stat, tags) { | ||
var _this = this; | ||
return new Promise(function (resolve) { | ||
_this.statsd.increment(stat, 1, _this.normalizeTags(tags), _this.createCallback(resolve)); | ||
} | ||
increment(stat, tags) { | ||
return new Promise(resolve => { | ||
this.statsd.increment(stat, 1, this.normalizeTags(tags), this.createCallback(resolve)); | ||
}); | ||
}; | ||
StatsDClient.prototype.close = function () { | ||
var _this = this; | ||
return new Promise(function (resolve) { | ||
_this.statsd.close(_this.createCallback(resolve)); | ||
} | ||
close() { | ||
return new Promise(resolve => { | ||
this.statsd.close(this.createCallback(resolve)); | ||
}); | ||
}; | ||
StatsDClient.prototype.addGlobalTags = function (globalTags) { | ||
} | ||
addGlobalTags(globalTags) { | ||
this.statsd = this.statsd.childClient({ | ||
globalTags: this.normalizeTags(globalTags), | ||
}); | ||
}; | ||
StatsDClient.prototype.createCallback = function (resolve) { | ||
var _this = this; | ||
return function (error) { | ||
if (error && _this.options.errorHandler) { | ||
_this.options.errorHandler(error); | ||
} | ||
createCallback(resolve) { | ||
return (error) => { | ||
if (error && this.options.errorHandler) { | ||
this.options.errorHandler(error); | ||
} | ||
resolve(); | ||
}; | ||
}; | ||
StatsDClient.prototype.normalizeTags = function (tags) { | ||
var e_1, _a; | ||
if (tags === void 0) { tags = []; } | ||
} | ||
normalizeTags(tags = []) { | ||
if (Array.isArray(tags)) { | ||
return 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; | ||
} | ||
const output = {}; | ||
for (const [key, value] of Object.entries(tags)) { | ||
const newValue = value == null ? UNKNOWN : String(value); | ||
if (this.options.snakeCase) { | ||
output[snakeCase(key)] = newValue; | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
else { | ||
output[key] = newValue; | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return output; | ||
}; | ||
return StatsDClient; | ||
}()); | ||
exports.StatsDClient = StatsDClient; | ||
} | ||
} |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var client_1 = require("./client"); | ||
Object.defineProperty(exports, "StatsDClient", { enumerable: true, get: function () { return client_1.StatsDClient; } }); | ||
export { StatsDClient } from './client'; |
@@ -8,4 +8,12 @@ # Changelog | ||
## [2.1.2] - 2021-03-03 | ||
<!-- ## Unreleased --> | ||
## 2.1.4 - 2021-04-13 | ||
### Changed | ||
- Removed dependency on tslib, as we no-longer compile with `tsc`. [#1829](https://github.com/Shopify/quilt/pull/1829) | ||
## 2.1.2 - 2021-03-03 | ||
### Fixed | ||
@@ -15,3 +23,3 @@ | ||
## [2.1.0] - 2020-12-18 | ||
## 2.1.0 - 2020-12-18 | ||
@@ -22,7 +30,7 @@ ### Added | ||
## [2.0.1] - 2020-10-20 | ||
## 2.0.1 - 2020-10-20 | ||
- Added `tslib@^1.14.1` in the list of dependencies. [#1657](https://github.com/Shopify/quilt/pull/1657) | ||
## [2.0.0] - 2019-12-24 | ||
## 2.0.0 - 2019-12-24 | ||
@@ -37,3 +45,3 @@ ### Changed | ||
## [1.2.0] - 2019-12-24 | ||
## 1.2.0 - 2019-12-24 | ||
@@ -44,3 +52,3 @@ ### Added | ||
## [1.1.0] - 2019-10-08 | ||
## 1.1.0 - 2019-10-08 | ||
@@ -51,3 +59,3 @@ ### Added | ||
## [1.0.0] - 2019-10-07 | ||
## 1.0.0 - 2019-10-07 | ||
@@ -54,0 +62,0 @@ ### Added |
{ | ||
"name": "@shopify/statsd", | ||
"version": "2.1.3", | ||
"version": "2.1.4", | ||
"license": "MIT", | ||
@@ -8,5 +8,2 @@ "description": "An opinionated StatsD client for Shopify Node.js servers and other StatsD utilities", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"build": "tsc --p tsconfig.json" | ||
}, | ||
"sideEffects": false, | ||
@@ -29,4 +26,3 @@ "publishConfig": { | ||
"change-case": "^4.1.1", | ||
"hot-shots": "^8.2.0", | ||
"tslib": "^1.14.1" | ||
"hot-shots": "^8.2.0" | ||
}, | ||
@@ -33,0 +29,0 @@ "files": [ |
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
2
29101
453
- Removedtslib@^1.14.1
- Removedtslib@1.14.1(transitive)