DispatchObserver
interface in meocord/interface Since 4.1.0
interface DispatchObserverObserves every call MeoCord dispatches, as it starts and once it has settled, for metrics and audit logs.
Implement it on a class marked with Observer. It hears about commands, components, modals,
autocomplete, message, reaction and event handlers, and interactions no handler matches and nothing else
answers; a message no handler matches is not a call. For work inside a call, such as a span around a query,
use an interceptor.
Where it runs
- Observers: onStart — in
onStart, before anything else runs - Observers: onSettled — in
onSettled, once the call has settled
Members
onStart
onStart?(context: ExecutionContext): voidReceives a call as it begins, before @Defer and the guards, for a call that reached a handler; an
interaction no handler matches gets only onSettled. It is not waited for, and one that throws is
logged. onSettled for the same call receives the same context object, so a WeakMap keyed by it
pairs the two.
For spans around work inside the handler, such as a database query under the command's span, use an interceptor: an observer sees the call from outside, and nothing that runs within it.
Parameters
| Name | Type | Description |
|---|---|---|
context | ExecutionContext | The call's context. |
onSettled
onSettled(
context: ExecutionContext,
result: DispatchResult,
): void | Promise<void>Receives one settled call.
Parameters
| Name | Type | Description |
|---|---|---|
context | ExecutionContext | The call's context: its handler, arguments and metadata. For an interaction no handler matched, it has no controller or handler. |
result | DispatchResult | How the call ended, and how long it took. |
Returns
void | Promise<void>See also
- Observer
- DispatchResult