@saflib/node
@saflib/node
Interfaces
Interface | Description |
---|---|
Auth | Auth object passed in with every authenticated request. |
ErrorCollectorParam | Parameters provided to error collectors. |
ErrorReportOptions | Subset of properties given to Sentry or similar error reporting services. https://docs.sentry.io/platforms/javascript/guides/node/apis/#captureException |
LoggerOptions | Context to give for a logger, which doesn't include properties that are global. |
SafContext | Static, serializable context about what's currently going on. These should always be available in backend systems. |
SafContextWithAuth | Convenience type for when the context needs to have auth. |
SafReporters | Clients for reporting various sorts of telemetry. They're expected to be instantiated with a SafContext, so that context is included. |
Type Aliases
Type Alias | Description |
---|---|
ErrorCollector | Collectors take errors reported to them and propagate them to telemetry services such as Sentry. |
ErrorLevels | Taken from Sentry, excluding "log" which seems superfluous and vague |
ErrorReporter | The function that application logic has access to for reporting errors. |
LoggerContext | Context to give for a logger, which doesn't include properties that are global. |
SubsystemName | List of allowed subsystem names to be used as context for logging and such. |
Variables
Variable | Description |
---|---|
defaultErrorReporter | Default ErrorReporter; call addErrorCollector with this to use it. |
metricHistogramDefaultBuckets | - |
safContextStorage | Storage for SafContext. |
safReportersStorage | AsyncLocalStorage for SafReporters. |
testContext | Context provided during testing. |
Functions
Function | Description |
---|---|
addErrorCollector | Adds a callback for when errors are reported by the application. |
addLokiTransport | Adds a transport to the logger that sends logs to Loki. TODO: use env variables. |
addTransport | For production, when the application starts, it should add any transports using this function. Then all SAF-based applications will log to winston and they'll propagate to loggers such as Loki. |
collectSystemMetrics | Call when the application starts. Calls prom-client's collectDefaultMetrics function under the hood. |
createLogger | Creates a child logger with the specified request ID. Any servers or processors should use this to create a unique logger for each request or job or what have you. However, if not "instantiating" the request, you should use the request ID provided by the caller, such as in the proto envelope, so that requests which span processes can be correlated. |
createSilentLogger | Create a logger that doesn't print anything. |
generateRequestId | Generates a request ID. Only necessary for "requests" which are not initiated by proxy servers, such as for cron or async jobs. |
getSafContext | Convenience function for getting SafContext store. Errors if not found, returns testContext if in test mode. |
getSafContextWithAuth | Convenience function for getting SafContext store with auth. Errors if either the store is not found, or auth is not included. |
getSafReporters | Convenience method for getting the SafReporters from the storage. Errors if not found. |
getServiceName | Getter for service name. |
makeSubsystemErrorReporter | During setup, subsystems should use this to create their own set of reporters. "Operation name" should be the name of the function. |
makeSubsystemReporters | Creates a new SafReporters object for a given subsystem and operation. |
setServiceName | Sets the service name. Should be called as soon as the process starts. This is provided in SafContext and to instrumentation. |