From c535127b45bead933e59cf0db8d83ad074af520f Mon Sep 17 00:00:00 2001 From: Adam Shannon Date: Wed, 24 Dec 2025 09:55:12 -0600 Subject: [PATCH] fix: set version from IBM/sarama, not main app We are experiencing connection errors with a hosted Kafka vendor who is inspecting ClientSoftwareVersion. Currently this version is "v0.34.1" -- our application's version, but Sarama is on v1.46.3 which is what the vendor expects to see. This behavior matches franz-go as well: https://github.com/twmb/franz-go/blob/v1.20.6/pkg/kgo/config.go#L480 Signed-off-by: Adam Shannon --- version.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/version.go b/version.go index d3b9d53ff..548ac574b 100644 --- a/version.go +++ b/version.go @@ -1,6 +1,7 @@ package sarama import ( + "reflect" "runtime/debug" "sync" ) @@ -12,9 +13,18 @@ var ( func version() string { vOnce.Do(func() { + // Determine our package name without hardcoding a string + type getPackageName struct{} + thisPackagePath := reflect.TypeFor[getPackageName]().PkgPath() + bi, ok := debug.ReadBuildInfo() if ok { - v = bi.Main.Version + for _, dep := range bi.Deps { + if dep.Path == thisPackagePath { + v = dep.Version + break + } + } } if v == "" || v == "(devel)" { // if we can't read a go module version then they're using a git