Add environment-driven OpenTelemetry initialization#32
Conversation
Callers currently have to rebuild the same provider, exporter, propagation, and shutdown wiring, which makes OpenTelemetry setup inconsistent across Kenn tools. Centralize that bootstrap around the standard contrib mechanisms while keeping export opt-in. This avoids surprising attempts to connect to a localhost OTLP endpoint when a CLI or development tool has not explicitly configured a signal exporter, without replacing OpenTelemetry's native resource and provider extension points. Generated with Codex
roborev: Combined Review (
|
Resource defaults and provider construction both consult the OpenTelemetry environment, but the default resource is process-cached and its merge precedence can obscure a later environment value. Read environment attributes during each telemetry initialization before applying caller resource options. This makes OTEL resource configuration explicit and ensures deliberate caller attributes retain final precedence. Generated with Codex
roborev: Combined Review (
|
Merging fresh environment attributes over resource.Default still retained labels that the process-cached default had read earlier and that operators later removed. Construct the standard service, environment, and SDK resource afresh for each initialization, then apply caller options. Treat partial environment parsing as a warning so valid labels remain usable without turning malformed optional metadata into an application startup failure. Generated with Codex
roborev: Combined Review (
|
Default baggage propagation on OpenTelemetry 1.43 is vulnerable to oversized-header CPU, memory, and log amplification, so the helper must not expose callers to the affected parser. Upgrade the aligned OpenTelemetry and contrib modules to their patched releases. Keep recoverable environment parsing isolated from caller detectors, and preserve the SDK service-instance feature gate so resource hardening does not change identity cardinality. Generated with Codex
roborev: Combined Review (
|
Why
Kenn tools currently have to recreate OpenTelemetry provider, exporter, propagation, and shutdown wiring in each application. That makes standard environment-driven configuration harder to adopt consistently and leaves lifecycle/error handling up to every caller.
The standard
autoexportfallback would also attempt OTLP export to localhost when no exporter selector is configured. That is a poor default for reusable CLI and developer-tool infrastructure, where telemetry should remain inert until the operator explicitly enables a signal.Approach
Provide one app-neutral initializer for traces and metrics that preserves standard OpenTelemetry environment variables and native SDK option types. The only deliberate policy difference is that unset trace and metric exporter selectors mean off; explicit
otlp,console,prometheus, andnonevalues retain contrib behavior. Logs remain on the existingslogpath.Initialization registers globals only after all fallible setup succeeds, cleans up partial setup, and returns one shutdown function that attempts both providers without hiding either error.
Validation
go build ./...go tool gotestsum --format pkgname-and-test-fails -- ./...— 583 passed, 2 expected skipsgo vet ./...golangci-lint run ./telemetry/...— 0 issuesgit diff --checkRepo-wide
golangci-lint run ./...still reports three pre-existing findings ingit/cmdandvector/sqlitevec; this change introduces no telemetry lint findings.generated by a clanker