Skip to content

@btravstack/observability


@btravstack/observability / index

index ​

Classes ​

LoggerConfig ​

Defined in: observability/src/observability.ts:21

What the graph bound from the environment: the level every logger in it filters at. A port of its own, like a starter's HttpConfig, so anything that wants to know reads it rather than re-deriving it.

Extends ​

Constructors ​

Constructor ​
ts
new LoggerConfig(): LoggerConfig;

Defined in: di/dist/index.d.mts:15

Returns ​

LoggerConfig

Inherited from ​

Port("LoggerConfig")<LoggerSettings>.constructor

Properties ​

PropertyModifierTypeInherited fromDefined in
[ID]readonly"LoggerConfig"Port("LoggerConfig").[ID]di/dist/index.d.mts:11
[SERVICE]readonlyLoggerSettingsPort("LoggerConfig").[SERVICE]di/dist/index.d.mts:12
portIdstatic readonly"LoggerConfig"Port("LoggerConfig").portIddi/dist/index.d.mts:16

Type Aliases ​

Line ​

ts
type Line = object;

Defined in: observability/src/logger.ts:10

One line, as the implementation hands it to a Sink: the message, its severity, and everything known about it.

Properties ​

PropertyModifierTypeDescriptionDefined in
attributesreadonlyAttributes-observability/src/logger.ts:13
causereadonlyunknown-observability/src/logger.ts:14
levelreadonlyLevel-observability/src/logger.ts:11
messagereadonlystring-observability/src/logger.ts:12
timereadonlynumberMilliseconds since the epoch, stamped when the line was written.observability/src/logger.ts:16
unitreadonly| { tenantId?: string; traceId: string; unitId: string; } | undefinedWhat currentUnit() carried, or undefined outside a unit.observability/src/logger.ts:18

LoggerSettings ​

ts
type LoggerSettings = object;

Defined in: observability/src/config.ts:32

What observability() binds from the environment.

Properties ​

PropertyModifierTypeDefined in
levelreadonlyLevelobservability/src/config.ts:32

ObservabilityOptions ​

ts
type ObservabilityOptions = object;

Defined in: observability/src/observability.ts:23

Properties ​

PropertyModifierTypeDescriptionDefined in
level?readonlyLevelPins the level instead of reading LOG_LEVEL — a test's "fatal", a CLI's "debug".observability/src/observability.ts:31
sink?readonlySinkWhere lines go. Default: one JSON object per line on stdout. The @btravstack/observability/pino subpath is the same seam for a deployment that wants pino's throughput.observability/src/observability.ts:29

Sink ​

ts
type Sink = (line) => void;

Defined in: observability/src/logger.ts:24

Where a line goes. Given a Line, writes it — and never throws, which createLogger guarantees on its behalf.

Parameters ​

ParameterType
lineLine

Returns ​

void

Functions ​

createLogger() ​

ts
function createLogger(sink, level?): LoggerService;

Defined in: observability/src/logger.ts:41

A logger over sink, filtered at level and correlated with the ambient unit.

The correlation is read per call, not captured: one logger is built per scope and every unit the kernel opens has its own record, so a logger that captured it at construction would stamp the wrong trace id on every line but the first. with layers attributes and nothing else, so a child costs one object and shares the sink.

Every path is wrapped: a sink that throws is swallowed here, because a logger that takes the process down is worse than a line nobody sees.

Parameters ​

ParameterTypeDefault value
sinkSinkundefined
level?Level"info"

Returns ​

LoggerService


jsonSink() ​

ts
function jsonSink(stream?): Sink;

Defined in: observability/src/json-sink.ts:74

One JSON object per line on stream.

The caller's attributes are spread FIRST and the line's own fields after them, and that order is the precedence: an attributes: { level: "info" } cannot rewrite an error line's severity, nor its traceId.

The unit's ids are spread at the top level rather than nested under unit, because traceId is the field an operator searches.

Parameters ​

ParameterTypeDefault value
stream?{ write: (chunk) => unknown; }process.stdout
stream.write(chunk) => unknownundefined

Returns ​

Sink


kernelEvents() ​

ts
function kernelEvents(logger): EventSink;

Defined in: observability/src/observability.ts:100

The kernel's nine lifecycle events, as log lines on logger — the adapter between StartOptions.onEvent and an application's own stream.

The mapping is deliberate rather than mechanical: startFailed and uncaught are error, teardownError is warn (the application is already stopping and the exit code says so), everything else info. Each event's own fields become attributes, so a drain is queryable by field.

The logger is a PARAMETER, not resolved: building is emitted while the graph is still being built, so the sink cannot come from the context it watches.

Parameters ​

ParameterType
loggerLoggerService

Returns ​

EventSink


logLevel() ​

ts
function logLevel(options?): ConfigField<Level>;

Defined in: observability/src/config.ts:16

LOG_LEVEL, as a ConfigField of the six levels and nothing else.

A value outside the set is a ConfigInvalid naming the variable — exit 78 under runMain, before a line is written — rather than a silent fallback to info: a deployment that meant debug and typed verbose should be told, not quietly under-logged for a week. Built on Config.string, so it inherits the semantics every other variable has: an unset variable takes the default, a set-but-blank one is an error.

Parameters ​

ParameterType
options?{ default?: Level; }
options.default?Level

Returns ​

ConfigField<Level>


observability() ​

ts
function observability(options?): Module<LoggerConfig | Logger | Observers, ConfigInvalid, EnvReading<never, "LOG_LEVEL">>;

Defined in: observability/src/observability.ts:43

The observability starter: a module providing the application's Logger and the LoggerConfig it was built from. Import it next to the application and export Logger.

Every line carries the ambient unit's traceId, because the logger reads currentUnit() per call — so a request's lines are attributable with no argument threaded through the call stack.

Parameters ​

ParameterType
options?ObservabilityOptions

Returns ​

Module<LoggerConfig | Logger | Observers, ConfigInvalid, EnvReading<never, "LOG_LEVEL">>

Released under the MIT License.