Skip to content

Commit e981417

Browse files
committed
Add client host to application info
1 parent c817cad commit e981417

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

cluster.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"errors"
3131
"fmt"
3232
"net"
33+
"os"
3334
"runtime"
3435
"strconv"
3536
"strings"
@@ -151,20 +152,27 @@ func (cluster *mongoCluster) isMaster(socket *mongoSocket, result *isMasterResul
151152
// https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#connection-handshake
152153
//
153154
socket.sendMeta.Do(func() {
154-
var meta = bson.M{
155-
"driver": bson.M{
156-
"name": "mgo",
157-
"version": "globalsign",
158-
},
159-
"os": bson.M{
160-
"type": runtime.GOOS,
161-
"architecture": runtime.GOARCH,
162-
},
155+
var meta = bson.D{
156+
{"driver", bson.D{
157+
{"name", "mgo"},
158+
{"version", "globalsign"},
159+
}},
160+
{"os", bson.D{
161+
{"type", runtime.GOOS},
162+
{"architecture", runtime.GOARCH},
163+
}},
163164
}
164165

165166
// Include the application name if set
167+
application := bson.D{}
166168
if cluster.dialInfo.AppName != "" {
167-
meta["application"] = bson.M{"name": cluster.dialInfo.AppName}
169+
application = append(application, bson.DocElem{"name", cluster.dialInfo.AppName})
170+
}
171+
if hostname, err := os.Hostname(); err == nil {
172+
application = append(application, bson.DocElem{"host", hostname})
173+
}
174+
if len(application) > 0 {
175+
meta = append(meta, bson.DocElem{"application", application})
168176
}
169177

170178
cmd = append(cmd, bson.DocElem{

0 commit comments

Comments
 (0)