1.9 KiB
1.9 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
Architecture
- Module:
git.codelab.vc/pkg/obsx, Go 1.24, depends on OpenTelemetry and Prometheus client_golang - Single package
obsx
Core patterns
- SetupTracer — creates OTLP gRPC exporter, builds
sdktrace.TracerProviderwith batcher and ratio sampler, sets it as globalotel.TracerProvider - StartSpan — convenience function using
otel.Tracer("obsx")to start spans via the global provider - TracerConfig — service name, version, OTLP endpoint, sampling ratio;
defaults()setsSamplerto 1.0 if unset - Metrics — factory that creates Prometheus
CounterVec,HistogramVec,GaugeVecwith consistent namespace/subsystem - NewMetrics — creates an isolated
prometheus.Registrypre-loaded with process and Go collectors - Handler() — returns
promhttp.HandlerForusing the isolated registry - Registry() — exposes the underlying
*prometheus.Registryfor direct access
Tracer lifecycle
SetupTracerreturnsshutdown func(context.Context) error— must be called to flush pending spans- Shutdown is the
TracerProvider.Shutdownmethod directly
Conventions
- Struct-based configs (
TracerConfig,MetricsConfig) withdefaults()methods - Isolated Prometheus registry — not the global default, avoids conflicts in tests and multi-tenant setups
nilbuckets inHistogram()defaults toprometheus.DefBuckets- No functional options — direct struct configuration only
See also
AGENTS.md— universal AI agent guide with package map and common tasks