Skip to content

Commit

Permalink
Send client version in user-agent (#63)
Browse files Browse the repository at this point in the history
* Send client version in user-agent
  • Loading branch information
tellet-q authored Dec 17, 2024
1 parent 1501be6 commit 268df71
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions qdrant/grpc_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package qdrant

import (
"fmt"
"os/exec"
"strings"

"google.golang.org/grpc"
)

Expand Down Expand Up @@ -30,9 +34,11 @@ func NewDefaultGrpcClient() (*GrpcClient, error) {
func NewGrpcClient(config *Config) (*GrpcClient, error) {
// We append config.GrpcOptions in the end
// so that user's explicit options take precedence
clientVersion := getClientVersion()
config.GrpcOptions = append([]grpc.DialOption{
config.getTransportCreds(),
config.getAPIKeyInterceptor(),
grpc.WithUserAgent(fmt.Sprintf("go-client/%s", clientVersion)),
}, config.GrpcOptions...)

conn, err := grpc.NewClient(config.getAddr(), config.GrpcOptions...)
Expand Down Expand Up @@ -84,3 +90,13 @@ func (c *GrpcClient) Snapshots() SnapshotsClient {
func (c *GrpcClient) Close() error {
return c.conn.Close()
}

func getClientVersion() string {
packageName := "github.com/qdrant/go-client"
cmd := exec.Command("go", "list", "-m", "-f", "{{.Version}}", packageName)
output, err := cmd.Output()
if err != nil {
return "Unknown"
}
return strings.TrimSpace(string(output))
}

0 comments on commit 268df71

Please sign in to comment.