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 InjectToOutgoingContext(ctx context.Context, correlationID string) context.Context
- func StreamClientCorrelationInterceptor(opts ...ClientCorrelationInterceptorOption) grpc.StreamClientInterceptor
- func StreamServerCorrelationInterceptor() grpc.StreamServerInterceptor
- func UnaryClientCorrelationInterceptor(opts ...ClientCorrelationInterceptorOption) grpc.UnaryClientInterceptor
- func UnaryServerCorrelationInterceptor() grpc.UnaryServerInterceptor
- type ClientCorrelationInterceptorOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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() 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() grpc.UnaryServerInterceptor
UnaryServerCorrelationInterceptor propagates Correlation-IDs from incoming upstream services
Types ¶
type ClientCorrelationInterceptorOption ¶
type ClientCorrelationInterceptorOption func(*clientInterceptConfig)
ClientCorrelationInterceptorOption will configure a correlation handler currently there are no options, but this gives us the option to extend the interface in a backwards compatible way
func WithClientName ¶
func WithClientName(clientName string) ClientCorrelationInterceptorOption
WithClientName will configure the client name metadata on the GRPC client interceptors