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)
| 131 | // setupStubServer creates a stub server with OpenTelemetry component configured on client |
| 132 | // and server side and returns the server. |
| 133 | func 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 |
no test coverage detected