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>
45 lines
3.1 KiB
Markdown
45 lines
3.1 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/` (opt-in via `Admin.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 — 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
|