Files
obsx/CLAUDE.md
T
M.ShakhmatovandClaude Fable 5.2 8837e8d316
CI / test (push) Successful in 1m12s
Deprecate v1.0.0 HTTP and log helpers in favour of the toolkit API
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>
2026-11-15 16:43:33 +03:00

45 lines
3.0 KiB
Markdown

# CLAUDE.md — obsx
## Commands
```bash
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; `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 (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: `HTTPTransport` and `LogHandler` delegate to the new implementations, `HTTPMiddleware` keeps its own metrics `http_requests_total` / `http_request_duration_seconds` under 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; `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
- 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 — 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