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

Function setupStubServer

stats/opentelemetry/e2e_test.go:133–163  ·  view source on GitHub ↗

setupStubServer creates a stub server with OpenTelemetry component configured on client and server side and returns the server.

(t *testing.T, metricsOptions *opentelemetry.MetricsOptions, traceOptions *experimental.TraceOptions)

Source from the content-addressed store, hash-verified

131// setupStubServer creates a stub server with OpenTelemetry component configured on client
132// and server side and returns the server.
133func setupStubServer(t *testing.T, metricsOptions *opentelemetry.MetricsOptions, traceOptions *experimental.TraceOptions) *stubserver.StubServer {
134 ss := &stubserver.StubServer{
135 UnaryCallF: func(_ context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
136 return &testpb.SimpleResponse{Payload: &testpb.Payload{
137 Body: make([]byte, len(in.GetPayload().GetBody())),
138 }}, nil
139 },
140 FullDuplexCallF: func(stream testgrpc.TestService_FullDuplexCallServer) error {
141 for {
142 _, err := stream.Recv()
143 if err == io.EOF {
144 return nil
145 }
146 }
147 },
148 }
149
150 otelOptions := opentelemetry.Options{}
151 if metricsOptions != nil {
152 otelOptions.MetricsOptions = *metricsOptions
153 }
154 if traceOptions != nil {
155 otelOptions.TraceOptions = *traceOptions
156 }
157
158 if err := ss.Start([]grpc.ServerOption{opentelemetry.ServerOption(otelOptions)},
159 opentelemetry.DialOption(otelOptions)); err != nil {
160 t.Fatalf("Error starting endpoint server: %v", err)
161 }
162 return ss
163}
164
165// waitForTraceSpans waits until the in-memory span exporter has received the
166// expected trace spans based on span name and kind. It polls the exporter at a

Calls 7

StartMethod · 0.95
ServerOptionFunction · 0.92
DialOptionFunction · 0.92
RecvMethod · 0.65
FatalfMethod · 0.65
GetBodyMethod · 0.45
GetPayloadMethod · 0.45

Tested by

no test coverage detected