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

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/[email protected]
yarn add @shopify/[email protected]
yarn add @shopify/[email protected]

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/[email protected]
yarn add @shopify/[email protected]
yarn add @shopify/[email protected]

@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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants