-
Notifications
You must be signed in to change notification settings - Fork 8
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
Decorators #45
base: main
Are you sure you want to change the base?
Decorators #45
Conversation
return function (_target: Object, propertyKey: string, descriptor: PropertyDescriptor) { | ||
const originalMethod = descriptor.value; | ||
const metricName = `${prefix}${prefix ? '.' : ''}${propertyKey}`; | ||
descriptor.value = monitored(metricName, originalMethod, options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
descriptor.value = monitored(metricName, originalMethod, options); | |
descriptor.value = (...args) => monitored(metricName, () => originalMethod(...args), options); |
monitored calls the method, you need descriptor.value
to be a method
}, | ||
"include": ["src/**/*", "types/*.d.ts"], | ||
"include": ["src/**/*", "types/*.d.ts", "example/**/*"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ensure that it does not cause examples
to be part of the dist
/** | ||
* @deprecated since version 2.0 | ||
*/ | ||
export const getStatsdClient: Monitor['getStatsdClient'] = (...args) => getGlobalInstance().getStatsdClient(...args); | ||
export const increment: Monitor['increment'] = (...args) => getGlobalInstance().increment(...args); | ||
export const gauge: Monitor['gauge'] = (...args) => getGlobalInstance().gauge(...args); | ||
export const timing: Monitor['timing'] = (...args) => getGlobalInstance().timing(...args); | ||
|
||
export const monitorMethod = <T>(prefix?: string, options: MonitoredOptions<T> = {}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd replace monitorMethod
with a function
(instead of const) and provide an overload which does not take the prefix parameter.
I want to avoid @monitorMethod(undefined, {...})
.
Or, just make prefix
required. What use cases do we have that we don't add some prefix to your monitor call?
Which issues does it affect?
What it does