@@ -119,7 +119,7 @@ func Connect(ctx context.Context, params *ConnParams) (*Conn, error) {
119
119
// make any read or write just return with an error
120
120
// right away.
121
121
status <- connectResult {
122
- err : c .clientHandshake (params ),
122
+ err : c .clientHandshake (ctx , params ),
123
123
}
124
124
}()
125
125
@@ -201,8 +201,8 @@ func (c *Conn) Ping() error {
201
201
// clientHandshake handles the client side of the handshake.
202
202
// Note the connection can be closed while this is running.
203
203
// 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" )
206
206
defer span .Finish ()
207
207
208
208
// if EnableQueryInfo is set, make sure that all queries starting with the handshake
@@ -212,11 +212,16 @@ func (c *Conn) clientHandshake(params *ConnParams) error {
212
212
}
213
213
214
214
// Wait for the server initial handshake packet, and parse it.
215
+ spanReadPacket , ctx := trace .NewSpan (ctx , "Conn.clientHandshake.readPackage" )
215
216
data , err := c .readPacket ()
217
+ spanReadPacket .Finish ()
216
218
if err != nil {
217
219
return NewSQLError (CRServerLost , "" , "initial packet read failed: %v" , err )
218
220
}
221
+
222
+ spanParseHandshakePakcet , ctx := trace .NewSpan (ctx , "Conn.clientHandshake.parseInitialHandshakePacket" )
219
223
capabilities , salt , err := c .parseInitialHandshakePacket (data )
224
+ spanParseHandshakePakcet .Finish ()
220
225
if err != nil {
221
226
return err
222
227
}
@@ -235,13 +240,16 @@ func (c *Conn) clientHandshake(params *ConnParams) error {
235
240
c .Capabilities = capabilities & (CapabilityClientDeprecateEOF )
236
241
}
237
242
243
+ spanParseConnCharset , ctx := trace .NewSpan (ctx , "Conn.clientHandshake.ParseConnectionCharset" )
238
244
charset , err := collations .Local ().ParseConnectionCharset (params .Charset )
245
+ spanParseConnCharset .Finish ()
239
246
if err != nil {
240
247
return err
241
248
}
242
249
243
250
// Handle switch to SSL if necessary.
244
251
if params .SslEnabled () {
252
+ spanSslEnabled , ctx := trace .NewSpan (ctx , "Conn.clientHandshake.spanSslEnabled" )
245
253
// If client asked for SSL, but server doesn't support it,
246
254
// stop right here.
247
255
if params .SslRequired () && capabilities & CapabilityClientSSL == 0 {
@@ -285,6 +293,8 @@ func (c *Conn) clientHandshake(params *ConnParams) error {
285
293
c .conn = conn
286
294
c .bufferedReader .Reset (conn )
287
295
c .Capabilities |= CapabilityClientSSL
296
+
297
+ spanSslEnabled .Finish ()
288
298
}
289
299
290
300
// Password encryption.
@@ -320,6 +330,8 @@ func (c *Conn) clientHandshake(params *ConnParams) error {
320
330
// If the server didn't support DbName in its handshake, set
321
331
// it now. This is what the 'mysql' client does.
322
332
if capabilities & CapabilityClientConnectWithDB == 0 && params .DbName != "" {
333
+ spanWriteDbName , _ := trace .NewSpan (ctx , "Conn.clientHandshake.spanWriteDbName" )
334
+ defer spanWriteDbName .Finish ()
323
335
// Write the packet.
324
336
if err := c .writeComInitDB (params .DbName ); err != nil {
325
337
return err
0 commit comments