d108-go

module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: MIT

README

d108-go

The Go library of the d108 observability contract: identity, failure, logging, paths, atomicfile, work, tracing, metrics, httpserver, lifecycle, cli, doctor, config and secrets. The contract (standard.md, schema, golden corpus, logcheck) is the private repo github.com/AndreiD108/d108; CLAUDE.md maps this module. MIT license.

Use it

go get github.com/AndreiD108/d108-go@v0.1.1

The module is public. v0.1.1 is the first version that builds without credentials; v0.1.0 still requires the private logcheck module.

Releases

Tags vX.Y.Z on main. v0.1.0 (2026-10-29) was the first; the API can still change before the JS and Python libraries settle it.

Develop

make test             # go test ./...
make sync-contract    # copy cases.json, the schema and secrets.json from ../d108

The tests check written lines against the contract with the logcheck binary of the private contract repo (package contracttest). Without logcheck on PATH those checks skip and the rest of the suite runs. To install it (needs access to the private repo):

GOPRIVATE='github.com/AndreiD108/*' go install github.com/AndreiD108/d108/logcheck/cmd/logcheck@v0.1.0

GOPRIVATE keeps go away from the public proxy and checksum database for the private module; git also needs credentials for https://github.com (gh auth setup-git, or git config --global url.git@github.com:.insteadOf https://github.com/).

make sync-contract copies the contract files by hand from a checkout of the private d108 next to this one; internal/golden fails while the copies differ from it, and skips that comparison when the checkout is absent.

Directories

Path Synopsis
Package atomicfile writes a file through a temp file and a rename, so a reader sees the old content or the new content, never a partial file.
Package atomicfile writes a file through a temp file and a rename, so a reader sees the old content or the new content, never a partial file.
cli
Package cli builds the Cobra tree of a tool by standard.md section 9.2: Root makes the root with the persistent --format flag and the doctor subcommand, Group makes a command that only holds subcommands, Command makes a leaf.
Package cli builds the Cobra tree of a tool by standard.md section 9.2: Root makes the root with the persistent --format flag and the doctor subcommand, Group makes a command that only holds subcommands, Command makes a leaf.
clitest
Package clitest runs a tree made with cli in a test: one call gives the exit code, stdout and stderr of a command, and Lines gives the log lines it wrote.
Package clitest runs a tree made with cli in a test: one call gives the exit code, stdout and stderr of a command, and Lines gives the log lines it wrote.
Package config loads an app's settings (standard.md section 9.5): a struct filled from `<Config>/config.json` by its json tags, then from the environment by its env tags, with `go-envconfig` as the one parser for both.
Package config loads an app's settings (standard.md section 9.5): a struct filled from `<Config>/config.json` by its json tags, then from the environment by its env tags, with `go-envconfig` as the one parser for both.
Package contracttest checks log lines against the d108 contract in a test.
Package contracttest checks log lines against the d108 contract in a test.
Package doctor builds the report behind every tool's `doctor` subcommand (standard.md section 9.2): where the log lines go and why, the level and its source, the current log file, whether the agent answers on 127.0.0.1:4317, whether tracing is on, the version and the instance id.
Package doctor builds the report behind every tool's `doctor` subcommand (standard.md section 9.2): where the log lines go and why, the level and its source, the current log file, whether the agent answers on 127.0.0.1:4317, whether tracing is on, the version and the instance id.
Package failure classes errors and maps the classes to the shared exit-code table of standard.md section 9.2.
Package failure classes errors and maps the classes to the shared exit-code table of standard.md section 9.2.
Package httpserver wraps http.Server with the request middleware of work (one request.handled per request, a span, panic recovery), GET /healthz, optional CORS and optional pprof.
Package httpserver wraps http.Server with the request middleware of work (one request.handled per request, a span, panic recovery), GET /healthz, optional CORS and optional pprof.
Package identity names the running program once: service.name, service.version, service.instance.id and the pid.
Package identity names the running program once: service.name, service.version, service.instance.id and the pid.
internal
otelres
Package otelres builds the OTel resource tracing and metrics share, and holds their common on/off switch.
Package otelres builds the OTel resource tracing and metrics share, and holds their common on/off switch.
Package lifecycle owns main: Run sets up logging, tracing and metrics from the identity, writes process.start, runs the app's function and takes every exit through one stop sequence (standard.md section 9.1).
Package lifecycle owns main: Run sets up logging, tracing and metrics from the identity, writes process.start, runs the app's function and takes every exit through one stop sequence (standard.md section 9.1).
internal/run
Package run is the state of one lifecycle run and its stop sequence, shared by lifecycle (the process owner) and lifecycletest (the in-process harness).
Package run is the state of one lifecycle run and its stop sequence, shared by lifecycle (the process owner) and lifecycletest (the in-process harness).
lifecycletest
Package lifecycletest runs a lifecycle.Func through the real stop sequence inside a test, so a service test sees its OnStop steps, Go goroutines and Stop calls behave as they do under lifecycle.Run: ctx cancelled, the Go goroutines drained, the steps in reverse order, fn waited for, process.stop or process.crash as the last line.
Package lifecycletest runs a lifecycle.Func through the real stop sequence inside a test, so a service test sees its OnStop steps, Go goroutines and Stop calls behave as they do under lifecycle.Run: ctx cancelled, the Go goroutines drained, the steps in reverse order, fn waited for, process.stop or process.crash as the last line.
Package logging writes the JSON line of standard.md section 2 through log/slog: output selection by environment, level, dated files with retention and a size cap, the 64 KiB line limit, text rendering on stderr, and per-work attributes read from the context.
Package logging writes the JSON line of standard.md section 2 through log/slog: output selection by environment, level, dated files with retention and a size cap, the 64 KiB line limit, text rendering on stderr, and per-work attributes read from the context.
Package metrics turns the OTel metric SDK on when OTEL_EXPORTER_OTLP_ENDPOINT is set and leaves it a no-op otherwise.
Package metrics turns the OTel metric SDK on when OTEL_EXPORTER_OTLP_ENDPOINT is set and leaves it a no-op otherwise.
Package paths resolves the six per-app directories of standard.md section 9.3 on Linux and macOS.
Package paths resolves the six per-app directories of standard.md section 9.3 on Linux and macOS.
Package secrets keeps an app's secrets (standard.md section 9.5): API tokens and anything else that may not sit in plain text.
Package secrets keeps an app's secrets (standard.md section 9.5): API tokens and anything else that may not sit in plain text.
Package tracing turns the OTel trace SDK on when OTEL_EXPORTER_OTLP_ENDPOINT is set and leaves it a no-op otherwise.
Package tracing turns the OTel trace SDK on when OTEL_EXPORTER_OTLP_ENDPOINT is set and leaves it a no-op otherwise.
Package work is the unit of work of standard.md section 4: one wide event per CLI command run (command.run) and per handled request (request.handled, from the HTTP middleware or from Request for a socket or RPC server), a span that continues the caller's trace, attributes gathered while the unit runs, TRACEPARENT for child processes and job.progress for long jobs.
Package work is the unit of work of standard.md section 4: one wide event per CLI command run (command.run) and per handled request (request.handled, from the HTTP middleware or from Request for a socket or RPC server), a span that continues the caller's trace, attributes gathered while the unit runs, TRACEPARENT for child processes and job.progress for long jobs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL