-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Problem:
configgrpc
and confighttp
both allow setting a headers
section to set headers on client requests. However, while confighttp
handles this internally, configgrpc
does not, as there doesn't seem to be a way to set headers on the grpc.ClientConn
struct it returns. The OTLP/gRPC exporter fills the gap by extracting the headers
config, wrapping it in a metadata.MD
, then later adding it to the Context
passed to the gRPC call, which is then taken into account by the gRPC library.
This is not ideal, as it means the configgrpc.ClientConfig.Headers
is a no-op by default, and components using a gRPC client must manually do this abstraction-leaking processing to take it into account.
Proposed solution:
I considered wrapping grpc.ClientConn
to automatically add the metadata in Invoke
calls, but because the code calling this method is generated by protogen and expects a grpc.ClientConn
specifically, this does not seem possible.
My proposed solution is a new method on ClientConfig
which adds the headers to a provided Context
, and documenting that the Headers
field requires calling this function and passing the resulting Context
into the gRPC call.
Update: We can actually do it pretty simply with grpc.WithUnaryInterceptor
.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status