Created
February 24, 2022 14:43
-
-
Save TonPC64/e520cee4e297abdd3df30777ccdacb12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type server struct { | |
api.HelloServiceServer | |
} | |
func (s *server) SayHello(ctx context.Context, in *api.HelloRequest) (*api.HelloResponse, error) { | |
tracer := otel.GetTracerProvider().Tracer("webserver-grpc") | |
_, span := tracer.Start(ctx, "SayHello-span") | |
defer span.End() | |
fmt.Println(ctx) | |
log.Printf("Received: %v\n", in.GetGreeting()) | |
time.Sleep(50 * time.Millisecond) | |
return &api.HelloResponse{Reply: "Hello " + in.Greeting}, nil | |
} | |
func main() { | |
lis, err := net.Listen("tcp", ":"+os.Getenv("PORT")) | |
if err != nil { | |
log.Fatalf("failed to listen: %v", err) | |
} | |
s := grpc.NewServer( | |
grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor()), | |
grpc.StreamInterceptor(otelgrpc.StreamServerInterceptor()), | |
) | |
api.RegisterHelloServiceServer(s, &server{}) | |
if err := s.Serve(lis); err != nil { | |
log.Fatalf("failed to serve: %v", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment