Skip to content
Open
Show file tree
Hide file tree
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
37 changes: 29 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"io"
"net"
"os"
"runtime"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -35,6 +37,7 @@ type Client struct {
info proto.ClientHello
server proto.ServerHello
version clientVersion
hostname string
quotaKey string

mux sync.Mutex
Expand Down Expand Up @@ -447,15 +450,8 @@ func Connect(ctx context.Context, conn net.Conn, opt Options) (*Client, error) {
func ConnectWithBuffer(ctx context.Context, conn net.Conn, opt Options, buf *proto.Buffer) (*Client, error) {
opt.setDefaults()

clientName := proto.Name
pkg := pkgVersion.Get()
if opt.ClientName == "" {
if pkg.Name != "" {
clientName = fmt.Sprintf("%s (%s)", clientName, pkg.Name)
}
} else {
clientName = fmt.Sprintf("%s %s", clientName, opt.ClientName)
}
clientName := formatClientName(opt.ClientName, pkg)
ver := clientVersion{
Name: clientName,
Major: pkg.Major,
Expand Down Expand Up @@ -499,6 +495,7 @@ func ConnectWithBuffer(ctx context.Context, conn net.Conn, opt Options, buf *pro
if opt.SSHSigner != nil {
user = " SSH KEY AUTHENTICATION " + user
}
hostname, _ := os.Hostname()

c := &Client{
conn: conn,
Expand All @@ -510,6 +507,7 @@ func ConnectWithBuffer(ctx context.Context, conn net.Conn, opt Options, buf *pro
tracer: opt.tracer,
meter: opt.meter,
quotaKey: opt.QuotaKey,
hostname: hostname,

readTimeout: opt.ReadTimeout,

Expand Down Expand Up @@ -539,6 +537,29 @@ func ConnectWithBuffer(ctx context.Context, conn net.Conn, opt Options, buf *pro
return c, nil
}

func formatClientName(clientName string, pkg pkgVersion.Value) string {
libraryProduct := formatLibraryProduct(pkg)
metadata := formatClientMetadata()
if clientName == "" {
if pkg.Name != "" {
return fmt.Sprintf("%s (%s) %s", proto.Name, pkg.Name, metadata)
}
return fmt.Sprintf("%s %s", proto.Name, metadata)
}
return fmt.Sprintf("%s %s %s", clientName, libraryProduct, metadata)
}

func formatLibraryProduct(pkg pkgVersion.Value) string {
if pkg.Raw != "" {
return proto.Name + "/" + strings.TrimPrefix(pkg.Raw, "v")
}
return fmt.Sprintf("%s/%d.%d.%d", proto.Name, pkg.Major, pkg.Minor, pkg.Patch)
}

func formatClientMetadata() string {
return fmt.Sprintf("(lv:go/%s; os:%s)", strings.TrimPrefix(runtime.Version(), "go"), runtime.GOOS)
}

// A Dialer dials using a context.
type Dialer interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
Expand Down
2 changes: 1 addition & 1 deletion query.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (c *Client) sendQuery(ctx context.Context, q Query) error {
InitialQueryID: q.QueryID,
InitialAddress: c.conn.LocalAddr().String(),
OSUser: "",
ClientHostname: "",
ClientHostname: c.hostname,
ClientName: c.version.Name,

Span: trace.SpanContextFromContext(ctx),
Expand Down
Loading