CI / test (push) Failing after 43s
- Admin pprof is opt-in (AdminConfig.EnablePprof) - Client spans drop the URL query string; HostFunc bounds the host label - Config.HTTP/HTTPClient/GRPC configure the Observer's instrumentation - A panic after a partial HTTP response counts as 500 - GaugeFunc, CounterFunc and RegisterDBStats panic on duplicates - Abandoned client gRPC streams are recorded as Canceled - OTEL_EXPORTER_OTLP_PROTOCOL selects the protocol when unset - Health reports are cached for 1s; hung checks are not restarted - Environment is exported as deployment.environment.name Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
3.1 KiB
3.1 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/(opt-in viaAdmin.EnablePprof)
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