Skip to content

Commit d70389f

Browse files
committed
add more spans in client handshake
Signed-off-by: Austen Lacy <austen.lacy@shopify.com>
1 parent 879c17b commit d70389f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

go/mysql/client.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func Connect(ctx context.Context, params *ConnParams) (*Conn, error) {
119119
// make any read or write just return with an error
120120
// right away.
121121
status <- connectResult{
122-
err: c.clientHandshake(params),
122+
err: c.clientHandshake(ctx, params),
123123
}
124124
}()
125125

@@ -201,8 +201,8 @@ func (c *Conn) Ping() error {
201201
// clientHandshake handles the client side of the handshake.
202202
// Note the connection can be closed while this is running.
203203
// Returns a SQLError.
204-
func (c *Conn) clientHandshake(params *ConnParams) error {
205-
span, _ := trace.NewSpan(context.TODO(), "Conn.clientHandshake")
204+
func (c *Conn) clientHandshake(ctx context.Context, params *ConnParams) error {
205+
span, ctx := trace.NewSpan(ctx, "Conn.clientHandshake")
206206
defer span.Finish()
207207

208208
// if EnableQueryInfo is set, make sure that all queries starting with the handshake
@@ -212,11 +212,16 @@ func (c *Conn) clientHandshake(params *ConnParams) error {
212212
}
213213

214214
// Wait for the server initial handshake packet, and parse it.
215+
spanReadPacket, ctx := trace.NewSpan(ctx, "Conn.clientHandshake.readPackage")
215216
data, err := c.readPacket()
217+
spanReadPacket.Finish()
216218
if err != nil {
217219
return NewSQLError(CRServerLost, "", "initial packet read failed: %v", err)
218220
}
221+
222+
spanParseHandshakePakcet, ctx := trace.NewSpan(ctx, "Conn.clientHandshake.parseInitialHandshakePacket")
219223
capabilities, salt, err := c.parseInitialHandshakePacket(data)
224+
spanParseHandshakePakcet.Finish()
220225
if err != nil {
221226
return err
222227
}
@@ -235,13 +240,16 @@ func (c *Conn) clientHandshake(params *ConnParams) error {
235240
c.Capabilities = capabilities & (CapabilityClientDeprecateEOF)
236241
}
237242

243+
spanParseConnCharset, ctx := trace.NewSpan(ctx, "Conn.clientHandshake.ParseConnectionCharset")
238244
charset, err := collations.Local().ParseConnectionCharset(params.Charset)
245+
spanParseConnCharset.Finish()
239246
if err != nil {
240247
return err
241248
}
242249

243250
// Handle switch to SSL if necessary.
244251
if params.SslEnabled() {
252+
spanSslEnabled, ctx := trace.NewSpan(ctx, "Conn.clientHandshake.spanSslEnabled")
245253
// If client asked for SSL, but server doesn't support it,
246254
// stop right here.
247255
if params.SslRequired() && capabilities&CapabilityClientSSL == 0 {
@@ -285,6 +293,8 @@ func (c *Conn) clientHandshake(params *ConnParams) error {
285293
c.conn = conn
286294
c.bufferedReader.Reset(conn)
287295
c.Capabilities |= CapabilityClientSSL
296+
297+
spanSslEnabled.Finish()
288298
}
289299

290300
// Password encryption.
@@ -320,6 +330,8 @@ func (c *Conn) clientHandshake(params *ConnParams) error {
320330
// If the server didn't support DbName in its handshake, set
321331
// it now. This is what the 'mysql' client does.
322332
if capabilities&CapabilityClientConnectWithDB == 0 && params.DbName != "" {
333+
spanWriteDbName, _ := trace.NewSpan(ctx, "Conn.clientHandshake.spanWriteDbName")
334+
defer spanWriteDbName.Finish()
323335
// Write the packet.
324336
if err := c.writeComInitDB(params.DbName); err != nil {
325337
return err

0 commit comments

Comments
 (0)