MCPcopy
hub / github.com/grpc/grpc-go / main

Function main

examples/features/observability/server/main.go:54–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52}
53
54func main() {
55 // Turn on global telemetry for the whole binary. If a configuration is
56 // specified, any created gRPC Client Conn's or Servers will emit telemetry
57 // data according the configuration.
58 ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
59 defer cancel()
60 err := observability.Start(ctx)
61 if err != nil {
62 log.Fatalf("observability.Start() failed: %v", err)
63 }
64 defer observability.End()
65
66 flag.Parse()
67 lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
68 if err != nil {
69 log.Fatalf("failed to listen: %v", err)
70 }
71 s := grpc.NewServer()
72 pb.RegisterGreeterServer(s, &server{})
73 log.Printf("server listening at %v", lis.Addr())
74
75 // This server can potentially be terminated by an external signal from the
76 // Operating System. The following catches those signals and calls s.Stop().
77 // This causes the s.Serve() call to return and run main()'s defers,
78 // including the observability.End() call that ensures any pending
79 // observability data is sent to Cloud Operations.
80 c := make(chan os.Signal, 1)
81 signal.Notify(c, os.Interrupt, syscall.SIGTERM)
82 go func() {
83 <-c
84 s.Stop()
85 }()
86
87 if err := s.Serve(lis); err != nil {
88 log.Fatalf("failed to serve: %v", err)
89 }
90}

Callers

nothing calls this directly

Calls 9

StopMethod · 0.95
ServeMethod · 0.95
StartFunction · 0.92
EndFunction · 0.92
NewServerFunction · 0.92
FatalfMethod · 0.65
ParseMethod · 0.65
PrintfMethod · 0.65
AddrMethod · 0.45

Tested by

no test coverage detected