# 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 ``` ## Architecture - **Module**: `git.codelab.vc/pkg/obsx`, Go 1.26, depends on OpenTelemetry and Prometheus client_golang - **Single package** `obsx` ### Core patterns - **SetupTracer** — creates OTLP gRPC exporter (TLS unless `Insecure`), builds `sdktrace.TracerProvider` with batcher and parent-based ratio sampler, sets it and W3C propagators as OpenTelemetry globals - **StartSpan** — convenience function starting spans via the global provider - **TracerConfig** — service name, version, OTLP endpoint, insecure, headers, sampling ratio, resource attributes; `defaults()` sets `Sampler` to 1.0 if unset - **HTTPMiddleware** — server span + `http_requests_total` / `http_request_duration_seconds` per request; route label from `Request.Pattern` - **HTTPTransport** — `http.RoundTripper` with client spans and trace context injection - **LogHandler** — `slog.Handler` wrapper adding `trace_id` / `span_id` - **Metrics** — factory that creates Prometheus `CounterVec`, `HistogramVec`, `GaugeVec` with consistent namespace/subsystem - **NewMetrics** — creates an isolated `prometheus.Registry` pre-loaded with process and Go collectors - **Handler()** — returns `promhttp.HandlerFor` using the isolated registry - **Registry()** — exposes the underlying `*prometheus.Registry` for direct access ### Tracer lifecycle - `SetupTracer` returns `shutdown func(context.Context) error` — must be called to flush pending spans - Shutdown is the `TracerProvider.Shutdown` method directly ## Conventions - Struct-based configs (`TracerConfig`, `MetricsConfig`) with `defaults()` methods - Isolated Prometheus registry — not the global default, avoids conflicts in tests and multi-tenant setups - `nil` buckets in `Histogram()` defaults to `prometheus.DefBuckets` - No functional options — direct struct configuration only - Public API is stable since v1.0.0 — no breaking changes; record changes in `CHANGELOG.md` ## See also - `AGENTS.md` — universal AI agent guide with package map and common tasks