Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2743 from Shopify/restricted-statsd-client-metrics
Browse files Browse the repository at this point in the history
Generic type for StatsDClient to accept restrictions
  • Loading branch information
ryanwilsonperkin authored Apr 1, 2024
2 parents 77671e5 + f910328 commit 48bd90e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-bees-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/statsd': minor
---

Allow restriction on allowed metric names in StatsDClient
16 changes: 9 additions & 7 deletions packages/statsd/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface MetricOptions {

export type Options = ClientOptions | ChildOptions;

export class StatsDClient {
export class StatsDClient<Stat extends string = string> {
protected statsd: StatsD;
protected logger: Logger = console;
protected options: ClientOptions;
Expand Down Expand Up @@ -77,7 +77,7 @@ export class StatsDClient {
}

distribution(
stat: string | string[],
stat: Stat | Stat[],
value: number,
tags?: Tags,
options: MetricOptions = {},
Expand All @@ -94,7 +94,7 @@ export class StatsDClient {
}

timing(
stat: string | string[],
stat: Stat | Stat[],
value: number,
tags?: Tags,
options: MetricOptions = {},
Expand All @@ -111,7 +111,7 @@ export class StatsDClient {
}

gauge(
stat: string | string[],
stat: Stat | Stat[],
value: number,
tags?: Tags,
options: MetricOptions = {},
Expand All @@ -128,7 +128,7 @@ export class StatsDClient {
}

increment(
stat: string | string[],
stat: Stat | Stat[],
tags?: Tags,
options: MetricOptions = {},
value = 1,
Expand All @@ -150,8 +150,10 @@ export class StatsDClient {
});
}

childClient(options?: Omit<ChildOptions, 'client'>) {
return new StatsDClient({client: this, ...options});
childClient<ChildStat extends string = Stat>(
options?: Omit<ChildOptions, 'client'>,
) {
return new StatsDClient<ChildStat>({client: this, ...options});
}

addGlobalTags(globalTags: Tags) {
Expand Down

0 comments on commit 48bd90e

Please sign in to comment.