From 8895b1b2b24d30fa2662f6e9643d2d4d49650bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Tue, 4 Feb 2025 09:23:57 +0100 Subject: [PATCH] client: Set _client_version connection attribute --- client/conn.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/client/conn.go b/client/conn.go index 9cdf93afc..310146415 100644 --- a/client/conn.go +++ b/client/conn.go @@ -7,6 +7,7 @@ import ( "fmt" "net" "runtime" + "runtime/debug" "strings" "time" @@ -101,12 +102,19 @@ func ConnectWithDialer(ctx context.Context, network, addr, user, password, dbNam c.BufferSize = defaultBufferSize c.attributes = map[string]string{ - "_client_name": "go-mysql", - // "_client_version": "0.1", + "_client_name": "go-mysql", "_os": runtime.GOOS, "_platform": runtime.GOARCH, "_runtime_version": runtime.Version(), } + if buildInfo, ok := debug.ReadBuildInfo(); ok { + for _, bi := range buildInfo.Deps { + if bi.Path == "github.com/go-mysql-org/go-mysql" { + c.attributes["_client_version"] = bi.Version + break + } + } + } if network == "" { network = getNetProto(addr)