From ea29e75dea1ddc07c8317693368a30c3cd00c0dc Mon Sep 17 00:00:00 2001 From: Aleksander Zaruczewski Date: Tue, 9 Apr 2024 16:09:09 +0300 Subject: [PATCH] feat(client): user-agent telemetry --- .github/workflows/release.yml | 14 ++++++++++++++ client.go | 11 ++++++++++- version.go | 6 ++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 version.go diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b61af68..efe0503 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,6 +27,20 @@ jobs: GITHUB_TOKEN: ${{ github.token }} WITH_V: true DRY_RUN: true + - run: | + tee version.go << END + package aiven + + // Version returns aiven-go-client version string + func Version() string { + return "${{ steps.version.outputs.new_tag }}" + } + END + git config user.name github-actions + git config user.email github-actions@github.com + git add . + git commit -m "chore(version.go): update go-client-codegen version" + git push - id: sha run: | GIT_SHA=$(git rev-parse HEAD) diff --git a/client.go b/client.go index e6e85ca..ff00579 100644 --- a/client.go +++ b/client.go @@ -6,10 +6,12 @@ import ( "context" "encoding/json" "errors" + "fmt" "io" "net/http" "os" "reflect" + "strings" "time" "github.com/hashicorp/go-multierror" @@ -128,7 +130,14 @@ func (d *aivenClient) do(ctx context.Context, method, path string, v any) (*http } req.Header.Set("Content-Type", "application/json") - req.Header.Set("User-Agent", d.UserAgent) + req.Header.Set( + "User-Agent", + strings.TrimSpace(fmt.Sprintf( + "go-client-codegen/%s %s", + strings.TrimLeft(Version(), "v"), + d.UserAgent, + )), + ) req.Header.Set("Authorization", "aivenv1 "+d.Token) // TODO: BAD hack to get around pagination in most cases diff --git a/version.go b/version.go new file mode 100644 index 0000000..64b33d8 --- /dev/null +++ b/version.go @@ -0,0 +1,6 @@ +package aiven + +// Version returns aiven-go-client version string +func Version() string { + return "v0.4.0" +}