diff --git a/client.go b/client.go index 0088662f7..566db6cd3 100644 --- a/client.go +++ b/client.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "fmt" + "github.com/opentracing/opentracing-go" "golang.org/x/crypto/ssh" ) @@ -52,6 +53,9 @@ func WithTLSConfig(tlsConfig *tls.Config) ClientOption { // JoinWorkspace connects the client to the server's Live Share // workspace and returns a session representing their connection. func (c *Client) JoinWorkspace(ctx context.Context) (*Session, error) { + span, ctx := opentracing.StartSpanFromContext(ctx, "Client.JoinWorkspace") + defer span.Finish() + clientSocket := newSocket(c.connection, c.tlsConfig) if err := clientSocket.connect(ctx); err != nil { return nil, fmt.Errorf("error connecting websocket: %v", err) @@ -120,6 +124,9 @@ func (s *Session) openStreamingChannel(ctx context.Context, id channelID) (ssh.C return nil, fmt.Errorf("error getting stream id: %v", err) } + span, ctx := opentracing.StartSpanFromContext(ctx, "Session.OpenChannel+SendRequest") + defer span.Finish() + channel, reqs, err := s.ssh.conn.OpenChannel("session", nil) if err != nil { return nil, fmt.Errorf("error opening ssh channel for transport: %v", err) diff --git a/port_forwarder.go b/port_forwarder.go index dc91222ed..7d3363ba2 100644 --- a/port_forwarder.go +++ b/port_forwarder.go @@ -5,6 +5,8 @@ import ( "fmt" "io" "net" + + "github.com/opentracing/opentracing-go" ) // A PortForwarder forwards TCP traffic over a LiveShare session from a port on a remote @@ -108,6 +110,9 @@ func awaitError(ctx context.Context, errc <-chan error) error { // handleConnection handles forwarding for a single accepted connection, then closes it. func (fwd *PortForwarder) handleConnection(ctx context.Context, id channelID, conn io.ReadWriteCloser) (err error) { + span, ctx := opentracing.StartSpanFromContext(ctx, "PortForwarder.handleConnection") + defer span.Finish() + defer safeClose(conn, &err) channel, err := fwd.session.openStreamingChannel(ctx, id) diff --git a/rpc.go b/rpc.go index 237606fe0..10aa2c7eb 100644 --- a/rpc.go +++ b/rpc.go @@ -6,6 +6,7 @@ import ( "io" "sync" + "github.com/opentracing/opentracing-go" "github.com/sourcegraph/jsonrpc2" ) @@ -26,6 +27,9 @@ func (r *rpcClient) connect(ctx context.Context) { } func (r *rpcClient) do(ctx context.Context, method string, args, result interface{}) error { + span, ctx := opentracing.StartSpanFromContext(ctx, method) + defer span.Finish() + waiter, err := r.Conn.DispatchCall(ctx, method, args) if err != nil { return fmt.Errorf("error dispatching %q call: %v", method, err)