2

How to log client connection to server for gRPC ?

That is on event when a client is connected, I should be able to get some basic information, like IP, version and log it

DATETIME connection from 192.168.1.1 AppName

Related to gRPC / Protobuf interface versioning

Community
  • 1
  • 1
Paul Verest
  • 60,022
  • 51
  • 208
  • 332

1 Answers1

3

Today, IP address and version is available on a per-RPC basis, but not when the client connects. You can use serverCall.attributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR) to get the IP address and the version is included in the User-Agent metadata.

Issue 2312 (v1.1) will add a mechanism to be notified of new connections. It would have access to the IP address of the client, but it wouldn't know the client version. Client version is only known on a per-RPC basis, due to things like proxies.

Paul Verest
  • 60,022
  • 51
  • 208
  • 332
Eric Anderson
  • 24,057
  • 5
  • 55
  • 76
  • What is "on a per-RPC basis"? Is it inside rpc call on server? – Paul Verest Nov 14 '16 at 17:34
  • When servicing a particular RPC, the server could detect the version of the client. But the version is not known when the connection is established, and one connection can include requests from multiple different clients (and thereby multiple different versions). – Eric Anderson Nov 23 '16 at 16:44
  • " one connection can include requests from multiple different clients " I awfully missed this base stuff. Can you point to exact docs page? – Paul Verest Nov 24 '16 at 14:56
  • 1
    It isn't in the docs really, because it isn't gRPC mixing clients and gRPC currently doesn't have features where the distinction is important. The mixing of clients comes from reverse proxies like nghttpx, which is a very common case when serving HTTP. – Eric Anderson Nov 28 '16 at 16:50