What happens
version and commitSHA are vars in internal/cli (root.go:9-10), set via -ldflags -X at build time. Any package that needs the version string must either import cli (which pulls in cobra, every subcommand, and all of cli's transitive dependencies) or receive it as a function parameter threaded from the call site.
Today telemetry.Setup() takes serviceVersion string as a parameter because internal/telemetry cannot import internal/cli without creating a cycle (cli already imports telemetry). The same threading happens in internal/binary/crosscompile.go, which reconstructs the ldflags path to inject the version into cross-compiled binaries.
What should happen
The two build-time vars and their accessors (Version(), CommitSHA()) should live in a dependency-free leaf package (e.g. internal/buildinfo) that any internal package can import without risk of cycles. The -ldflags -X paths in Makefile:102 and internal/binary/crosscompile.go:64 would update to point at the new package.
Callers that currently receive the version as a parameter (telemetry.Setup, and any future packages that need it) could import buildinfo directly instead of threading the value through multiple call sites.
Context
Came up during the OTel SDK migration (refactor/otel-sdk). telemetry.Setup needs the version to set service.version on the OTel resource, but can't import cli. Threading the string works, but as more packages need build metadata (the OTLP exporter, the OTel resource, user-agent headers), the parameter-passing accumulates. A leaf package removes the problem at the root.
What happens
versionandcommitSHAarevars ininternal/cli(root.go:9-10), set via-ldflags -Xat build time. Any package that needs the version string must either importcli(which pulls in cobra, every subcommand, and all ofcli's transitive dependencies) or receive it as a function parameter threaded from the call site.Today
telemetry.Setup()takesserviceVersion stringas a parameter becauseinternal/telemetrycannot importinternal/cliwithout creating a cycle (clialready importstelemetry). The same threading happens ininternal/binary/crosscompile.go, which reconstructs the ldflags path to inject the version into cross-compiled binaries.What should happen
The two build-time vars and their accessors (
Version(),CommitSHA()) should live in a dependency-free leaf package (e.g.internal/buildinfo) that any internal package can import without risk of cycles. The-ldflags -Xpaths inMakefile:102andinternal/binary/crosscompile.go:64would update to point at the new package.Callers that currently receive the version as a parameter (
telemetry.Setup, and any future packages that need it) could importbuildinfodirectly instead of threading the value through multiple call sites.Context
Came up during the OTel SDK migration (
refactor/otel-sdk).telemetry.Setupneeds the version to setservice.versionon the OTel resource, but can't importcli. Threading the string works, but as more packages need build metadata (the OTLP exporter, the OTel resource, user-agent headers), the parameter-passing accumulates. A leaf package removes the problem at the root.