EventHandlerFunction<T extends DiagnosticEvent> typedef
Function signature type for functions that handle a DiagnosticEvent.
Use together with AsEventHandler to adapt such a function to a DiagnosticEventHandler.
Implementing diagnostic event handlers
DiagnosticEventHandler implementations are typically provided by the developer to the Serverpod constructor upon startup.
Implementations can handle DiagnosticEvent instances of a specific type or context, or all events.
Guidelines
A DiagnosticEvent represents an event that occurs in the server. DiagnosticEventHandler implementations can react to these events in order to gain insights into the behavior of the server.
As the name suggests the handlers should perform diagnostics only, and not have any responsibilities that the regular functioning of the server depends on.
The registered handlers are typically run concurrently, can not depend on each other, and asynchronously - they are not awaited by the operation they are triggered from.
If a handler throws an exception it will be logged to stderr and otherwise ignored.
Time limits
Handlers should not run for an extended period of time. Permitting that would risk accumulating resource consumption and make the long-running performance of the server degrade. This is especially true in situations of high load or implementation issues causing a large number of events.
By default they are given a maximum of 30 seconds to complete. This can be overridden by setting the diagnostic handler timeout in the constructor of the Serverpod instance.
Implementation
typedef EventHandlerFunction<T extends DiagnosticEvent> = void Function(
T event, {
required OriginSpace space,
required DiagnosticEventContext context,
});