go-grpc-middleware
go-grpc-middleware copied to clipboard
v2: WithFieldExtractorForInitialReq equivalent
The old grpc_ctxtags interceptor had an option WithFieldExtractorForInitialReq, to extract the tags from the first message passed from client to server.
For client-streams and bidirectional-streams, you can use
WithFieldExtractorForInitialReqwhich will extract the tags from the first message passed from client to server. Note the tags will not be modified for subsequent requests, so this option only makes sense when the initial message establishes the meta-data for the stream. – https://pkg.go.dev/github.com/grpc-ecosystem/go-grpc-middleware/tags#hdr-Request_Context_Tags
Now that grpc_ctxtags has been removed, what would be the right way to do this?
grpc_ctxtags interceptor was removed. Custom tags can be added to logging fields using logging.InjectFields. Proto option to add logging field was clunky in practice and we don't see any use of it nowadays, so it's removed.
The README mentions that logging.InjectFields should be used, but can it be used to add fields using the content of the first message received on a stream?
I tried wrapping the stream, and setting the context of the wrapped stream in the RecvMsg on first message, but no luck, looks like the logging interceptor doesn't get the new context, even in the logging.FinishCall.