Add HTTPMiddleware, HTTPTransport and LogHandler; extend TracerConfig with Insecure, Headers and Attributes; install W3C propagators; parent-based sampling; end-to-end OTLP export tests; update dependencies (Go 1.26). Breaking since v0.2.0: the OTLP connection uses TLS unless Insecure is set. Co-Authored-By: Claude <noreply@anthropic.com>
2.3 KiB
2.3 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.26, depends on OpenTelemetry and Prometheus client_golang - Single package
obsx
Core patterns
- SetupTracer — creates OTLP gRPC exporter (TLS unless
Insecure), buildssdktrace.TracerProviderwith 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()setsSamplerto 1.0 if unset - HTTPMiddleware — server span +
http_requests_total/http_request_duration_secondsper request; route label fromRequest.Pattern - HTTPTransport —
http.RoundTripperwith client spans and trace context injection - LogHandler —
slog.Handlerwrapper addingtrace_id/span_id - 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
- 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