CI / test (push) Successful in 1m12s
LogHandler and HTTPTransport now delegate to NewTraceHandler and NewHTTPTransport. HTTPMiddleware keeps its v1.0.0 metric names but shares responseWriter and normalizeMethod with NewHTTPMiddleware. The package example shows obsx.New. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
3.0 KiB
3.0 KiB
CLAUDE.md — obsx
Commands
go build ./... # compile
go test ./... # all tests
go test -race ./... # tests with race detector
go test -v -run TestName ./... # single test
go vet ./... # static analysis
go run ./examples/service # example service (:8080, admin :9090)
Architecture
- Module:
git.codelab.vc/pkg/obsx, Go 1.26, depends on OpenTelemetry, Prometheus client_golang and gRPC-Go - Single package
obsx(+examples/service,deploy/with Grafana dashboard and Prometheus alerts)
Core patterns
- New / Observer — one call wires logger, tracer provider, metrics, health and optional admin server;
Shutdownflushes spans and stops the admin server - Config — service identity + per-component configs;
defaults()fills service name/version and propagates identity toTracing;WithEnv()appliesOBSX_*/OTEL_*overrides - NewLogger / TraceHandler — slog JSON/text logger;
TraceHandleraddstrace_id/span_idfrom context - SetupTracer / newTracerProvider — OTLP gRPC or HTTP exporter (TLS unless
Insecure; none when no endpoint),ParentBased(TraceIDRatioBased)sampler, resource with service/host attrs; sets global provider + TraceContext/Baggage propagator - HTTPMiddleware / HTTPTransport / LogHandler — the v1.0.0 API (
http.go,log.go), deprecated but must keep working:HTTPTransportandLogHandlerdelegate to the new implementations,HTTPMiddlewarekeeps its own metricshttp_requests_total/http_request_duration_secondsunder the namespace - StartSpan / Trace / RecordError / TraceID — span helpers on the global provider
- Metrics — Prometheus factory with namespace/subsystem, idempotent
register,Sub,GaugeFunc,CounterFunc,RegisterDBStats;base()gives a namespace-free factory for built-in metrics;observeattaches trace exemplars - NewHTTPMiddleware / NewHTTPTransport / NewGRPCInterceptors — server/client instrumentation: spans, propagation, RED metrics, access logs
- Health — liveness/readiness checks with timeouts, HTTP handlers,
grpc.health.v1server,SetReady - AdminHandler —
/metrics,/healthz,/livez,/readyz,/buildinfo,/loglevel,/debug/pprof/
Conventions
- Struct-based configs with
defaults()methods; no functional options - Public API is stable since v1.0.0 — no breaking changes; record changes in
CHANGELOG.md - Built-in metric names are fixed (no namespace) so dashboards/alerts in
deploy/work for every service — updatedeploy/, README and doc.go when adding or renaming them - Isolated Prometheus registry — not the global default
nilbuckets inHistogram()default toprometheus.DefBuckets- Bounded label cardinality: route templates,
OTHERfor unknown methods,unmatchedfor unknown routes - stdlib-only tests; restore otel/slog globals in tests that call
NeworSetupTracer
See also
AGENTS.md— package map, common tasks, gotchas