gitlab.com/gitlab-org/labkit@v1.21.0/correlation/grpc/server_interceptors_options.go (about) 1 package grpccorrelation 2 3 // The configuration for server correlation interceptors. 4 type serverInterceptConfig struct { 5 propagateIncomingCorrelationID bool 6 reversePropagateCorrelationID bool 7 } 8 9 // ServerCorrelationInterceptorOption configures server correlation interceptor. 10 type ServerCorrelationInterceptorOption func(*serverInterceptConfig) 11 12 func applyServerCorrelationInterceptorOptions(opts []ServerCorrelationInterceptorOption) serverInterceptConfig { 13 config := serverInterceptConfig{ 14 propagateIncomingCorrelationID: true, // enabled by default 15 } 16 for _, v := range opts { 17 v(&config) 18 } 19 20 return config 21 } 22 23 // WithoutPropagation disables correlation id propagation from incoming request metadata. 24 // If the id is missing or the interceptor is configured to not propagate it, a new id is generated and 25 // injected into the request context. 26 func WithoutPropagation() ServerCorrelationInterceptorOption { 27 return func(config *serverInterceptConfig) { 28 config.propagateIncomingCorrelationID = false 29 } 30 } 31 32 // WithReversePropagation enables server -> client correlation id propagation via response metadata. 33 // Client can then use the returned correlation id e.g. for logging purposes. 34 // It only makes sense to use this option together with WithoutPropagation i.e. in situations, when 35 // client-supplied correlation id is not trusted so server generates its own one and hence clients doesn't have it. 36 func WithReversePropagation() ServerCorrelationInterceptorOption { 37 return func(config *serverInterceptConfig) { 38 config.reversePropagateCorrelationID = true 39 } 40 }