go-grpc-middleware icon indicating copy to clipboard operation
go-grpc-middleware copied to clipboard

v2: WithFieldExtractorForInitialReq equivalent

Open fparga opened this issue 2 years ago • 1 comments

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 WithFieldExtractorForInitialReq which 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?

fparga avatar Jun 14 '23 23:06 fparga

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.

fparga avatar Jun 19 '23 20:06 fparga