Files
obsx/CLAUDE.md
T
Aleksey ShakhmatovandClaude 2c83b28342
CI / test (push) Successful in 1m17s
Publish / publish (push) Successful in 1m24s
Release v1.0.0: HTTP instrumentation, slog correlation, TLS by default
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>
2026-11-10 20:20:09 +03:00

47 lines
2.3 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
```
## 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