Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send client version in user-agent #63

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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...)
tellet-q marked this conversation as resolved.
Show resolved Hide resolved

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)
Anush008 marked this conversation as resolved.
Show resolved Hide resolved
output, err := cmd.Output()
if err != nil {
return "Unknown"
}
return strings.TrimSpace(string(output))
}
Loading