Documentation ¶
Overview ¶
Example (Client) ¶
package main import ( "log" grpccorrelation "gitlab.com/gitlab-org/labkit/correlation/grpc" "google.golang.org/grpc" ) func main() { // Add the interceptor to the grpc dialer dialer, err := grpc.Dial("https://gitaly-server.internal:9095", grpc.WithStreamInterceptor(grpccorrelation.StreamClientCorrelationInterceptor( grpccorrelation.WithClientName("my-client"), )), grpc.WithUnaryInterceptor(grpccorrelation.UnaryClientCorrelationInterceptor( grpccorrelation.WithClientName("my-client"), )), ) if err != nil { log.Fatalf("unable to dial: %v", err) } // Use the client connection with a protobuf service here... defer dialer.Close() }
Output:
Example (Server) ¶
package main import ( "log" "net" grpccorrelation "gitlab.com/gitlab-org/labkit/correlation/grpc" "google.golang.org/grpc" ) func main() { server := grpc.NewServer( grpc.StreamInterceptor(grpccorrelation.StreamServerCorrelationInterceptor()), grpc.UnaryInterceptor(grpccorrelation.UnaryServerCorrelationInterceptor()), ) listener, err := net.Listen("unix", "/tmp/grpc") if err != nil { log.Fatalf("unable to listen: %v", err) } server.Serve(listener) }
Output:
Index ¶
- func CorrelationIDFromMetadata(md metadata.MD) string
- func InjectToOutgoingContext(ctx context.Context, correlationID string) context.Context
- func StreamClientCorrelationInterceptor(opts ...ClientCorrelationInterceptorOption) grpc.StreamClientInterceptor
- func StreamServerCorrelationInterceptor(opts ...ServerCorrelationInterceptorOption) grpc.StreamServerInterceptor
- func UnaryClientCorrelationInterceptor(opts ...ClientCorrelationInterceptorOption) grpc.UnaryClientInterceptor
- func UnaryServerCorrelationInterceptor(opts ...ServerCorrelationInterceptorOption) grpc.UnaryServerInterceptor
- type ClientCorrelationInterceptorOption
- type ServerCorrelationInterceptorOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CorrelationIDFromMetadata ¶ added in v1.5.0
CorrelationIDFromMetadata can be used to extract correlation ID from request/response metadata. Returns an empty string if correlation ID is not found.
func InjectToOutgoingContext ¶
InjectToOutgoingContext will inject the correlation ID into the outgoing context metadata. Repeat calls will overwrite any existing correlation IDs.
func StreamClientCorrelationInterceptor ¶
func StreamClientCorrelationInterceptor(opts ...ClientCorrelationInterceptorOption) grpc.StreamClientInterceptor
StreamClientCorrelationInterceptor propagates Correlation-IDs downstream.
func StreamServerCorrelationInterceptor ¶
func StreamServerCorrelationInterceptor(opts ...ServerCorrelationInterceptorOption) grpc.StreamServerInterceptor
StreamServerCorrelationInterceptor propagates Correlation-IDs from incoming upstream services.
func UnaryClientCorrelationInterceptor ¶
func UnaryClientCorrelationInterceptor(opts ...ClientCorrelationInterceptorOption) grpc.UnaryClientInterceptor
UnaryClientCorrelationInterceptor propagates Correlation-IDs downstream.
func UnaryServerCorrelationInterceptor ¶
func UnaryServerCorrelationInterceptor(opts ...ServerCorrelationInterceptorOption) grpc.UnaryServerInterceptor
UnaryServerCorrelationInterceptor propagates Correlation-IDs from incoming upstream services.
Types ¶
type ClientCorrelationInterceptorOption ¶
type ClientCorrelationInterceptorOption func(*clientInterceptConfig)
ClientCorrelationInterceptorOption configures client correlation interceptors.
func WithClientName ¶
func WithClientName(clientName string) ClientCorrelationInterceptorOption
WithClientName will configure the client name metadata on the GRPC client interceptors.
type ServerCorrelationInterceptorOption ¶
type ServerCorrelationInterceptorOption func(*serverInterceptConfig)
ServerCorrelationInterceptorOption configures server correlation interceptor.
func WithReversePropagation ¶ added in v1.5.0
func WithReversePropagation() ServerCorrelationInterceptorOption
WithReversePropagation enables server -> client correlation id propagation via response metadata. Client can then use the returned correlation id e.g. for logging purposes. It only makes sense to use this option together with WithoutPropagation i.e. in situations, when client-supplied correlation id is not trusted so server generates its own one and hence clients doesn't have it.
func WithoutPropagation ¶
func WithoutPropagation() ServerCorrelationInterceptorOption
WithoutPropagation disables correlation id propagation from incoming request metadata. If the id is missing or the interceptor is configured to not propagate it, a new id is generated and injected into the request context.