@shopify/statsd
Advanced tools
Comparing version 4.0.1 to 4.1.0
@@ -10,6 +10,3 @@ 'use strict'; | ||
class StatsDClient { | ||
constructor({ | ||
logger, | ||
...options | ||
}) { | ||
constructor(options) { | ||
this.statsd = void 0; | ||
@@ -19,2 +16,21 @@ this.logger = console; | ||
if (isChildOptions(options)) { | ||
const { | ||
client, | ||
...childOptions | ||
} = options; | ||
this.logger = client.logger; | ||
this.options = { ...client.options, | ||
...childOptions | ||
}; | ||
this.statsd = client.statsd.childClient(childOptions); | ||
return; | ||
} | ||
const { | ||
logger, | ||
snakeCase, | ||
...statsdOptions | ||
} = options; | ||
if (logger) { | ||
@@ -25,3 +41,3 @@ this.logger = logger; | ||
this.options = { ...options, | ||
errorHandler: options.errorHandler ? options.errorHandler : error => { | ||
errorHandler: statsdOptions.errorHandler ? statsdOptions.errorHandler : error => { | ||
this.logger.log(`Error occurred in the StatsD client:\n${error.stack || error.message}`); | ||
@@ -63,2 +79,9 @@ } | ||
childClient(options) { | ||
return new StatsDClient({ | ||
client: this, | ||
...options | ||
}); | ||
} | ||
addGlobalTags(globalTags) { | ||
@@ -102,2 +125,6 @@ this.statsd = this.statsd.childClient({ | ||
function isChildOptions(options) { | ||
return 'client' in options; | ||
} | ||
exports.StatsDClient = StatsDClient; |
@@ -1,2 +0,2 @@ | ||
import { ClientOptions } from 'hot-shots'; | ||
import { StatsD, ClientOptions as HotShotClientOptions, ChildClientOptions as HotShotChildOptions } from 'hot-shots'; | ||
export interface Logger { | ||
@@ -8,11 +8,16 @@ log(message: string): void; | ||
} | string[]; | ||
export interface Options extends ClientOptions { | ||
export interface ClientOptions extends HotShotClientOptions { | ||
logger?: Logger; | ||
snakeCase?: boolean; | ||
} | ||
export interface ChildOptions extends HotShotChildOptions { | ||
client: StatsDClient; | ||
snakeCase?: boolean; | ||
} | ||
export declare type Options = ClientOptions | ChildOptions; | ||
export declare class StatsDClient { | ||
private statsd; | ||
private logger; | ||
private options; | ||
constructor({ logger, ...options }: Options); | ||
protected statsd: StatsD; | ||
protected logger: Logger; | ||
protected options: ClientOptions; | ||
constructor(options: Options); | ||
distribution(stat: string | string[], value: number, tags?: Tags): Promise<void>; | ||
@@ -23,2 +28,3 @@ timing(stat: string | string[], value: number, tags?: Tags): Promise<void>; | ||
close(): Promise<void>; | ||
childClient(options?: Omit<ChildOptions, 'client'>): StatsDClient; | ||
addGlobalTags(globalTags: Tags): void; | ||
@@ -25,0 +31,0 @@ private createCallback; |
export { StatsDClient } from './client'; | ||
export type { Logger, Options } from './client'; | ||
export type { Logger, Options, ClientOptions, ChildOptions } from './client'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@shopify/statsd", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"license": "MIT", | ||
@@ -28,3 +28,3 @@ "description": "An opinionated StatsD client for Shopify Node.js servers and other StatsD utilities", | ||
"change-case": "^4.1.1", | ||
"hot-shots": "^8.2.0" | ||
"hot-shots": "^9.3.0" | ||
}, | ||
@@ -31,0 +31,0 @@ "files": [ |
@@ -12,3 +12,3 @@ # `@shopify/statsd` | ||
```bash | ||
$ yarn add @shopify/statsd | ||
yarn add @shopify/statsd | ||
``` | ||
@@ -29,2 +29,3 @@ | ||
prefix: 'AppName', | ||
globalTags: {hello: 'world'}, | ||
}); | ||
@@ -45,2 +46,26 @@ ``` | ||
#### `timing` | ||
Represents the timing stat | ||
```javascript | ||
statsdClient.timing( | ||
'request_duration', | ||
100, // in milliseconds | ||
[], // user-defined tags to go with the data | ||
); | ||
``` | ||
#### `gauge` | ||
Represents the gauge stat | ||
```javascript | ||
statsdClient.gauge( | ||
'my_gauge', | ||
123.45, // value | ||
[], // user-defined tags to go with the data | ||
); | ||
``` | ||
#### `increment` | ||
@@ -65,1 +90,17 @@ | ||
``` | ||
#### `childClient` | ||
Create a child client and add more context to the client. | ||
The globalTags will be merged. | ||
The prefix and suffix will be concatenate using the `.` separator. | ||
```javascript | ||
statsdClient.childClient({ | ||
prefix: 'MyPrefix', | ||
suffix: 'MySuffix', | ||
globalTags: {foo: 'bar'}, | ||
}); | ||
``` | ||
In this example the prefix will be `AppName.NewPrefix`, the suffix will be `MySuffix` and the globalTags will be `{hello: 'world', foo: 'bar'}`. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
15033
239
103
+ Addedhot-shots@9.3.0(transitive)
- Removedhot-shots@8.5.2(transitive)
Updatedhot-shots@^9.3.0