Skip to content

@saflib/node


@saflib/node

Interfaces

InterfaceDescription
AuthAuth object passed in with every authenticated request.
ErrorCollectorParamParameters provided to error collectors.
ErrorReportOptionsSubset of properties given to Sentry or similar error reporting services. https://docs.sentry.io/platforms/javascript/guides/node/apis/#captureException
LoggerOptionsContext to give for a logger, which doesn't include properties that are global.
SafContextStatic, serializable context about what's currently going on. These should always be available in backend systems.
SafContextWithAuthConvenience type for when the context needs to have auth.
SafReportersClients for reporting various sorts of telemetry. They're expected to be instantiated with a SafContext, so that context is included.

Type Aliases

Type AliasDescription
ErrorCollectorCollectors take errors reported to them and propagate them to telemetry services such as Sentry.
ErrorLevelsTaken from Sentry, excluding "log" which seems superfluous and vague
ErrorReporterThe function that application logic has access to for reporting errors.
LoggerContextContext to give for a logger, which doesn't include properties that are global.
SubsystemNameList of allowed subsystem names to be used as context for logging and such.

Variables

VariableDescription
defaultErrorReporterDefault ErrorReporter; call addErrorCollector with this to use it.
metricHistogramDefaultBuckets-
safContextStorageStorage for SafContext.
safReportersStorageAsyncLocalStorage for SafReporters.
testContextContext provided during testing.

Functions

FunctionDescription
addErrorCollectorAdds a callback for when errors are reported by the application.
addLokiTransportAdds a transport to the logger that sends logs to Loki. TODO: use env variables.
addTransportFor 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.
collectSystemMetricsCall when the application starts. Calls prom-client's collectDefaultMetrics function under the hood.
createLoggerCreates 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.
createSilentLoggerCreate a logger that doesn't print anything.
generateRequestIdGenerates a request ID. Only necessary for "requests" which are not initiated by proxy servers, such as for cron or async jobs.
getSafContextConvenience function for getting SafContext store. Errors if not found, returns testContext if in test mode.
getSafContextWithAuthConvenience function for getting SafContext store with auth. Errors if either the store is not found, or auth is not included.
getSafReportersConvenience method for getting the SafReporters from the storage. Errors if not found.
getServiceNameGetter for service name.
makeSubsystemErrorReporterDuring setup, subsystems should use this to create their own set of reporters. "Operation name" should be the name of the function.
makeSubsystemReportersCreates a new SafReporters object for a given subsystem and operation.
setServiceNameSets the service name. Should be called as soon as the process starts. This is provided in SafContext and to instrumentation.