77 "fmt"
88 "io"
99 "io/ioutil"
10+ "os"
1011 "reflect"
1112 "sync"
1213 "sync/atomic"
@@ -20,6 +21,8 @@ const wsCancel = "xrpc.cancel"
2021const chValue = "xrpc.ch.val"
2122const chClose = "xrpc.ch.close"
2223
24+ var debugTrace = os .Getenv ("JSONRPC_ENABLE_DEBUG_TRACE" ) == "1"
25+
2326type frame struct {
2427 // common
2528 Jsonrpc string `json:"jsonrpc"`
@@ -132,6 +135,10 @@ func (c *wsConn) sendRequest(req request) error {
132135 c .writeLk .Lock ()
133136 defer c .writeLk .Unlock ()
134137
138+ if debugTrace {
139+ log .Debugw ("sendRequest" , "req" , req .Method , "id" , req .ID )
140+ }
141+
135142 if err := c .conn .WriteJSON (req ); err != nil {
136143 return err
137144 }
@@ -622,7 +629,7 @@ func (c *wsConn) handleWsConn(ctx context.Context) {
622629 var frame frame
623630 if err = json .NewDecoder (r ).Decode (& frame ); err == nil {
624631 if frame .ID , err = normalizeID (frame .ID ); err == nil {
625- action = fmt .Sprintf ("incoming(%s,%s )" , frame .Method , frame .ID )
632+ action = fmt .Sprintf ("incoming(%s,%v )" , frame .Method , frame .ID )
626633
627634 c .handleFrame (ctx , frame )
628635 go c .nextMessage ()
@@ -641,7 +648,7 @@ func (c *wsConn) handleWsConn(ctx context.Context) {
641648 return // failed to reconnect
642649 }
643650 case req := <- c .requests :
644- action = fmt .Sprintf ("send-request(%s)" , req .req .Method )
651+ action = fmt .Sprintf ("send-request(%s,%v )" , req .req .Method , req . req . ID )
645652
646653 c .writeLk .Lock ()
647654 if req .req .ID != nil {
@@ -701,6 +708,9 @@ func (c *wsConn) handleWsConn(ctx context.Context) {
701708 if c .pingInterval > 0 && time .Since (start ) > c .pingInterval * 2 {
702709 log .Warnw ("websocket long time no response" , "lastAction" , action , "time" , time .Since (start ))
703710 }
711+ if debugTrace {
712+ log .Debugw ("websocket action" , "lastAction" , action , "time" , time .Since (start ))
713+ }
704714 }
705715}
706716
0 commit comments