diff --git a/server.go b/server.go index 181e38cc1..e817f386b 100644 --- a/server.go +++ b/server.go @@ -291,6 +291,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. traceInfo.tr = trace.New("grpc.Recv."+methodFamily(stream.Method()), stream.Method()) defer traceInfo.tr.Finish() traceInfo.firstLine.client = false + traceInfo.firstLine.remoteAddr = t.RemoteAddr() traceInfo.tr.LazyLog(&traceInfo.firstLine, false) ctx = trace.NewContext(ctx, traceInfo.tr) defer func() { @@ -397,6 +398,7 @@ func (s *Server) processStreamingRPC(t transport.ServerTransport, stream *transp if ss.tracing { ss.traceInfo.tr = trace.New("grpc.Recv."+methodFamily(stream.Method()), stream.Method()) ss.traceInfo.firstLine.client = false + ss.traceInfo.firstLine.remoteAddr = t.RemoteAddr() ss.traceInfo.tr.LazyLog(&ss.traceInfo.firstLine, false) ss.ctx = trace.NewContext(ss.ctx, ss.traceInfo.tr) defer func() { diff --git a/transport/http2_server.go b/transport/http2_server.go index 057d93680..c9a2a36b2 100644 --- a/transport/http2_server.go +++ b/transport/http2_server.go @@ -689,3 +689,7 @@ func (t *http2Server) closeStream(s *Stream) { // other goroutines. s.cancel() } + +func (t *http2Server) RemoteAddr() net.Addr { + return t.conn.RemoteAddr() +} diff --git a/transport/transport.go b/transport/transport.go index 2dd38a83c..d33f2de7f 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -390,6 +390,8 @@ type ServerTransport interface { // should not be accessed any more. All the pending streams and their // handlers will be terminated asynchronously. Close() error + // RemoteAddr returns the remote network address. + RemoteAddr() net.Addr } // StreamErrorf creates an StreamError with the specified error code and description.