@@ -93,7 +93,7 @@ func newHandler(connCtx context.Context, conn jsonWriter, idgen func() ID, reg *
9393}
9494
9595// handleBatch executes all messages in a batch and returns the responses.
96- func (h * handler ) handleBatch (msgs []* jsonrpcMessage ) {
96+ func (h * handler ) handleBatch (ctx context. Context , msgs []* jsonrpcMessage ) {
9797 // Emit error response for empty batches:
9898 if len (msgs ) == 0 {
9999 h .startCallProc (func (cp * callProc ) {
@@ -116,7 +116,7 @@ func (h *handler) handleBatch(msgs []*jsonrpcMessage) {
116116 h .startCallProc (func (cp * callProc ) {
117117 answers := make ([]* jsonrpcMessage , 0 , len (msgs ))
118118 for _ , msg := range calls {
119- if answer := h .handleCallMsg (cp , msg ); answer != nil {
119+ if answer := h .handleCallMsg (cp , ctx , msg ); answer != nil {
120120 answers = append (answers , answer )
121121 }
122122 }
@@ -131,12 +131,12 @@ func (h *handler) handleBatch(msgs []*jsonrpcMessage) {
131131}
132132
133133// handleMsg handles a single message.
134- func (h * handler ) handleMsg (msg * jsonrpcMessage ) {
134+ func (h * handler ) handleMsg (ctx context. Context , msg * jsonrpcMessage ) {
135135 if ok := h .handleImmediate (msg ); ok {
136136 return
137137 }
138138 h .startCallProc (func (cp * callProc ) {
139- answer := h .handleCallMsg (cp , msg )
139+ answer := h .handleCallMsg (cp , ctx , msg )
140140 h .addSubscriptions (cp .notifiers )
141141 if answer != nil {
142142 h .conn .writeJSON (cp .ctx , answer )
@@ -287,7 +287,7 @@ func (h *handler) handleResponse(msg *jsonrpcMessage) {
287287}
288288
289289// handleCallMsg executes a call message and returns the answer.
290- func (h * handler ) handleCallMsg (ctx * callProc , msg * jsonrpcMessage ) * jsonrpcMessage {
290+ func (h * handler ) handleCallMsg (ctx * callProc , reqCtx context. Context , msg * jsonrpcMessage ) * jsonrpcMessage {
291291 start := time .Now ()
292292 switch {
293293 case msg .isNotification ():
@@ -297,7 +297,8 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMess
297297 case msg .isCall ():
298298 resp := h .handleCall (ctx , msg )
299299 if resp .Error != nil {
300- h .log .Warn ("Served " + msg .Method , "reqid" , idForLog {msg .ID }, "t" , time .Since (start ), "err" , resp .Error .Message )
300+ xForward := reqCtx .Value ("X-Forwarded-For" )
301+ h .log .Warn ("Served " + msg .Method , "reqid" , idForLog {msg .ID }, "t" , time .Since (start ), "err" , resp .Error .Message , "X-Forwarded-For" , xForward )
301302 } else {
302303 h .log .Debug ("Served " + msg .Method , "reqid" , idForLog {msg .ID }, "t" , time .Since (start ))
303304 }
0 commit comments