Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic type for StatsDClient to accept restrictions #2743

Merged
merged 2 commits into from
Apr 1, 2024

Conversation

ryanwilsonperkin
Copy link
Member

Description

It is often useful to be able to create a StatsDClient that has a well-defined Stat type parameter that restricts the types of stat that can be emitted. This allows us to create a list of allowed metrics in a single place and ensure that we're not emitting any others.

This preserves the existing behaviour by defaulting to string, but allows the creation of a StatsDClient parameterized with a string union or string enum to restrict to a subset.

For example

const client = new StatsDClient<'foo' | 'bar'>(...);

client.increment('foo', 1);  // valid
client.increment('bar', 1);  // valid
client.increment('baz', 1);  // invalid

It is often useful to be able to create a StatsDClient that has a
well-defined Stat type parameter that restricts the types of stat that
can be emitted. This allows us to create a list of allowed metrics in a
single place and ensure that we're not emitting any others.

This preserves the existing behaviour by defaulting to string, but
allows the creation of a StatsDClient parameterized with a string union
or string enum to restrict to a subset.

For example

```
const client = new StatsDClient<'foo' | 'bar'>(...);

client.increment('foo', 1);  // valid
client.increment('bar', 1);  // valid
client.increment('baz', 1);  // invalid
```
@ryanwilsonperkin
Copy link
Member Author

/snapit

Copy link
Contributor

github-actions bot commented Apr 1, 2024

🫰✨ Thanks @ryanwilsonperkin! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

yarn add @shopify/koa-metrics@0.0.0-snapshot-20240401130529
yarn add @shopify/koa-performance@0.0.0-snapshot-20240401130529
yarn add @shopify/statsd@0.0.0-snapshot-20240401130529

Default to the parent's type for Stat, but allow an override so that a
child client can be passed a different set of stats to use.
@ryanwilsonperkin
Copy link
Member Author

/snapit

Copy link
Contributor

github-actions bot commented Apr 1, 2024

🫰✨ Thanks @ryanwilsonperkin! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

yarn add @shopify/koa-metrics@0.0.0-snapshot-20240401141052
yarn add @shopify/koa-performance@0.0.0-snapshot-20240401141052
yarn add @shopify/statsd@0.0.0-snapshot-20240401141052

@ryanwilsonperkin ryanwilsonperkin merged commit 48bd90e into main Apr 1, 2024
9 checks passed
@ryanwilsonperkin ryanwilsonperkin deleted the restricted-statsd-client-metrics branch April 1, 2024 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants