gitlab.com/gitlab-org/labkit@v1.21.0/correlation/grpc/examples_test.go (about) 1 package grpccorrelation_test 2 3 import ( 4 "log" 5 "net" 6 7 grpccorrelation "gitlab.com/gitlab-org/labkit/correlation/grpc" 8 "google.golang.org/grpc" 9 ) 10 11 func Example_client() { 12 // Add the interceptor to the grpc dialer 13 dialer, err := grpc.Dial("https://gitaly-server.internal:9095", 14 grpc.WithStreamInterceptor(grpccorrelation.StreamClientCorrelationInterceptor( 15 grpccorrelation.WithClientName("my-client"), 16 )), 17 grpc.WithUnaryInterceptor(grpccorrelation.UnaryClientCorrelationInterceptor( 18 grpccorrelation.WithClientName("my-client"), 19 )), 20 ) 21 22 if err != nil { 23 log.Fatalf("unable to dial: %v", err) 24 } 25 26 // Use the client connection with a protobuf service here... 27 28 defer dialer.Close() 29 } 30 31 func Example_server() { 32 server := grpc.NewServer( 33 grpc.StreamInterceptor(grpccorrelation.StreamServerCorrelationInterceptor()), 34 grpc.UnaryInterceptor(grpccorrelation.UnaryServerCorrelationInterceptor()), 35 ) 36 37 listener, err := net.Listen("unix", "/tmp/grpc") 38 if err != nil { 39 log.Fatalf("unable to listen: %v", err) 40 } 41 42 server.Serve(listener) 43 }