Files
obsx/CLAUDE.md
T
M.ShakhmatovandClaude Opus 5.5 d1fc35fdf0
Publish / publish (push) Successful in 1m21s
Update documentation for the observability toolkit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 00:18:43 +03:00

2.6 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.25.7, 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; Shutdown flushes spans and stops the admin server
  • Config — service identity + per-component configs; defaults() fills service name/version and propagates identity to Tracing; WithEnv() applies OBSX_* / OTEL_* overrides
  • NewLogger / TraceHandler — slog JSON/text logger; TraceHandler adds trace_id/span_id from context
  • SetupTracer / newTracerProvider — OTLP gRPC or HTTP exporter (none when no endpoint), ParentBased(TraceIDRatioBased) sampler, resource with service/host attrs; sets global provider + TraceContext/Baggage propagator
  • 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; observe attaches trace exemplars
  • NewHTTPMiddleware / NewHTTPTransport / NewGRPCInterceptors — server/client instrumentation: spans, propagation, RED metrics, access logs
  • Health — liveness/readiness checks with timeouts, HTTP handlers, grpc.health.v1 server, SetReady
  • AdminHandler — /metrics, /healthz, /livez, /readyz, /buildinfo, /loglevel, /debug/pprof/

Conventions

  • Struct-based configs with defaults() methods; no functional options
  • Built-in metric names are fixed (no namespace) so dashboards/alerts in deploy/ work for every service — update deploy/, README and doc.go when adding or renaming them
  • Isolated Prometheus registry — not the global default
  • nil buckets in Histogram() default to prometheus.DefBuckets
  • Bounded label cardinality: route templates, OTHER for unknown methods, unmatched for unknown routes
  • stdlib-only tests; restore otel/slog globals in tests that call New or SetupTracer

See also

  • AGENTS.md — package map, common tasks, gotchas