Skip to content
GitHub

DispatchObserver

interface in meocord/interface Since 4.1.0

interface DispatchObserver

Observes 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

Members

onStart

onStart?(context: ExecutionContext): void

Receives 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. It runs before the call's server's and user's themes from themeFor are found, so respond() waits for them and useTheme() reads the handler's theme until then.

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

NameType
contextExecutionContext

The call's context.

onSettled

onSettled(
  context: ExecutionContext,
  result: DispatchResult,
): void | Promise<void>

Receives one settled call.

Parameters

NameType
contextExecutionContext

The call's context: its handler, arguments and metadata. For an interaction no handler matched, it has no controller or handler.

resultDispatchResult

How the call ended, and how long it took.

Returns

void | Promise<void>

See also