@dudousxd/nestjs-diagnostics
Version:
A standard convention for @dudousxd/nestjs-* libs to emit observability events over node:diagnostics_channel.
20 lines • 941 B
JavaScript
/** Metadata key under which a method's @OnDiagnostic subscriptions accumulate. */
export const ON_DIAGNOSTIC_META = Symbol('diagnostics:on');
/**
* Subscribe a provider method to a diagnostics channel. Requires
* `DiagnosticsModule.forRoot()` to be imported so the explorer wires it up.
*
* - `@OnDiagnostic('resilience', 'circuit-opened')` — the exact channel.
* - `@OnDiagnostic('resilience')` — every `aviary:resilience:*` channel (current + future).
*
* Stackable: apply more than once to react to several channels with one method.
*/
export function OnDiagnostic(lib, event) {
return (target, key) => {
const existing = Reflect.getMetadata(ON_DIAGNOSTIC_META, target, key) ??
[];
const meta = { lib, ...(event !== undefined ? { event } : {}) };
Reflect.defineMetadata(ON_DIAGNOSTIC_META, [...existing, meta], target, key);
};
}
//# sourceMappingURL=on-diagnostic.decorator.js.map