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

Method TestSpan

stats/opentelemetry/e2e_test.go:1006–1156  ·  view source on GitHub ↗

TestSpan verifies that the gRPC Trace Binary propagator correctly propagates span context between a client and server using the grpc- trace-bin header. It sets up a stub server with OpenTelemetry tracing enabled, makes a unary RPC, and streaming RPC as well. Verification: - Verifies that the span c

(t *testing.T)

Source from the content-addressed store, hash-verified

1004// - Verifies that the tracing information is recorded accurately in
1005// the OpenTelemetry backend.
1006func (s) TestSpan(t *testing.T) {
1007 mo, _ := defaultMetricsOptions(t, nil)
1008 // Using defaultTraceOptions to set up OpenTelemetry with an in-memory exporter.
1009 to, exporter := defaultTraceOptions(t)
1010 // Start the server with trace options.
1011 ss := setupStubServer(t, mo, to)
1012 defer ss.Stop()
1013
1014 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
1015 defer cancel()
1016
1017 // Make two RPC's, a unary RPC and a streaming RPC. These should cause
1018 // certain traces to be emitted, which should be observed through the
1019 // span exporter.
1020 if _, err := ss.Client.UnaryCall(ctx, &testpb.SimpleRequest{Payload: &testpb.Payload{
1021 Body: make([]byte, 10000),
1022 }}); err != nil {
1023 t.Fatalf("Unexpected error from UnaryCall: %v", err)
1024 }
1025 stream, err := ss.Client.FullDuplexCall(ctx)
1026 if err != nil {
1027 t.Fatalf("ss.Client.FullDuplexCall failed: %f", err)
1028 }
1029 stream.CloseSend()
1030 if _, err = stream.Recv(); err != io.EOF {
1031 t.Fatalf("stream.Recv received an unexpected error: %v, expected an EOF error", err)
1032 }
1033
1034 wantSpanInfos := []traceSpanInfo{
1035 {
1036 name: "Recv.grpc.testing.TestService.UnaryCall",
1037 spanKind: oteltrace.SpanKindServer.String(),
1038 status: otelcodes.Ok,
1039 attributes: nil,
1040 events: []trace.Event{
1041 {
1042 Name: "Inbound message",
1043 Attributes: []attribute.KeyValue{
1044 {
1045 Key: "sequence-number",
1046 Value: attribute.IntValue(0),
1047 },
1048 {
1049 Key: "message-size",
1050 Value: attribute.IntValue(10006),
1051 },
1052 },
1053 },
1054 {
1055 Name: "Outbound message",
1056 Attributes: []attribute.KeyValue{
1057 {
1058 Key: "sequence-number",
1059 Value: attribute.IntValue(0),
1060 },
1061 {
1062 Key: "message-size",
1063 Value: attribute.IntValue(10006),

Callers

nothing calls this directly

Calls 13

defaultMetricsOptionsFunction · 0.85
defaultTraceOptionsFunction · 0.85
setupStubServerFunction · 0.85
waitForTraceSpansFunction · 0.85
validateTracesFunction · 0.85
StopMethod · 0.65
UnaryCallMethod · 0.65
FatalfMethod · 0.65
FullDuplexCallMethod · 0.65
CloseSendMethod · 0.65
RecvMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected