diff --git a/stats/opentelemetry/client_tracing.go b/stats/opentelemetry/client_tracing.go index 8aea7c9deeb1..4ddaf095b7b0 100644 --- a/stats/opentelemetry/client_tracing.go +++ b/stats/opentelemetry/client_tracing.go @@ -60,7 +60,7 @@ func (h *clientStatsHandler) createCallTraceSpan(ctx context.Context, method str logger.Error("TraceProvider is not provided in trace options") return ctx, nil } - mn := strings.Replace(removeLeadingSlash(method), "/", ".", -1) + mn := "Sent." + strings.Replace(removeLeadingSlash(method), "/", ".", -1) tracer := h.options.TraceOptions.TracerProvider.Tracer(tracerName, trace.WithInstrumentationVersion(grpc.Version)) ctx, span := tracer.Start(ctx, mn, trace.WithSpanKind(trace.SpanKindClient)) return ctx, span diff --git a/stats/opentelemetry/e2e_test.go b/stats/opentelemetry/e2e_test.go index 809ff2c25cfc..3a6c52baf3d8 100644 --- a/stats/opentelemetry/e2e_test.go +++ b/stats/opentelemetry/e2e_test.go @@ -204,21 +204,28 @@ func validateTraces(t *testing.T, spans tracetest.SpanStubs, wantSpanInfos []tra for _, span := range spans { switch { - case span.Name == "grpc.testing.TestService.UnaryCall": + case span.Name == "Sent.grpc.testing.TestService.UnaryCall": isUnary = true if span.SpanKind == oteltrace.SpanKindClient { unaryClient = &span - } else { + } + case span.Name == "Recv.grpc.testing.TestService.UnaryCall": + isUnary = true + if span.SpanKind == oteltrace.SpanKindServer { unaryServer = &span } case span.Name == "Attempt.grpc.testing.TestService.UnaryCall": isUnary = true unaryAttempt = &span - case span.Name == "grpc.testing.TestService.FullDuplexCall": + + case span.Name == "Sent.grpc.testing.TestService.FullDuplexCall": isStream = true if span.SpanKind == oteltrace.SpanKindClient { streamClient = &span - } else { + } + case span.Name == "Recv.grpc.testing.TestService.FullDuplexCall": + isStream = true + if span.SpanKind == oteltrace.SpanKindServer { streamServer = &span } case span.Name == "Attempt.grpc.testing.TestService.FullDuplexCall": @@ -850,7 +857,7 @@ func (s) TestMetricsAndTracesOptionEnabled(t *testing.T) { wantSpanInfos := []traceSpanInfo{ { - name: "grpc.testing.TestService.UnaryCall", + name: "Recv.grpc.testing.TestService.UnaryCall", spanKind: oteltrace.SpanKindServer.String(), attributes: []attribute.KeyValue{ { @@ -872,7 +879,7 @@ func (s) TestMetricsAndTracesOptionEnabled(t *testing.T) { }, events: []trace.Event{ { - Name: "Inbound compressed message", + Name: "Inbound message", Attributes: []attribute.KeyValue{ { Key: "sequence-number", @@ -889,7 +896,7 @@ func (s) TestMetricsAndTracesOptionEnabled(t *testing.T) { }, }, { - Name: "Outbound compressed message", + Name: "Outbound message", Attributes: []attribute.KeyValue{ { Key: "sequence-number", @@ -930,7 +937,7 @@ func (s) TestMetricsAndTracesOptionEnabled(t *testing.T) { }, events: []trace.Event{ { - Name: "Outbound compressed message", + Name: "Outbound message", Attributes: []attribute.KeyValue{ { Key: "sequence-number", @@ -947,7 +954,7 @@ func (s) TestMetricsAndTracesOptionEnabled(t *testing.T) { }, }, { - Name: "Inbound compressed message", + Name: "Inbound message", Attributes: []attribute.KeyValue{ { Key: "sequence-number", @@ -966,13 +973,13 @@ func (s) TestMetricsAndTracesOptionEnabled(t *testing.T) { }, }, { - name: "grpc.testing.TestService.UnaryCall", + name: "Sent.grpc.testing.TestService.UnaryCall", spanKind: oteltrace.SpanKindClient.String(), attributes: nil, events: nil, }, { - name: "grpc.testing.TestService.FullDuplexCall", + name: "Recv.grpc.testing.TestService.FullDuplexCall", spanKind: oteltrace.SpanKindServer.String(), attributes: []attribute.KeyValue{ { @@ -995,7 +1002,7 @@ func (s) TestMetricsAndTracesOptionEnabled(t *testing.T) { events: nil, }, { - name: "grpc.testing.TestService.FullDuplexCall", + name: "Sent.grpc.testing.TestService.FullDuplexCall", spanKind: oteltrace.SpanKindClient.String(), attributes: nil, events: nil, @@ -1074,7 +1081,7 @@ func (s) TestSpan(t *testing.T) { wantSpanInfos := []traceSpanInfo{ { - name: "grpc.testing.TestService.UnaryCall", + name: "Recv.grpc.testing.TestService.UnaryCall", spanKind: oteltrace.SpanKindServer.String(), attributes: []attribute.KeyValue{ { @@ -1096,7 +1103,7 @@ func (s) TestSpan(t *testing.T) { }, events: []trace.Event{ { - Name: "Inbound compressed message", + Name: "Inbound message", Attributes: []attribute.KeyValue{ { Key: "sequence-number", @@ -1106,14 +1113,10 @@ func (s) TestSpan(t *testing.T) { Key: "message-size", Value: attribute.IntValue(10006), }, - { - Key: "message-size-compressed", - Value: attribute.IntValue(10006), - }, }, }, { - Name: "Outbound compressed message", + Name: "Outbound message", Attributes: []attribute.KeyValue{ { Key: "sequence-number", @@ -1123,10 +1126,6 @@ func (s) TestSpan(t *testing.T) { Key: "message-size", Value: attribute.IntValue(10006), }, - { - Key: "message-size-compressed", - Value: attribute.IntValue(10006), - }, }, }, }, @@ -1154,7 +1153,7 @@ func (s) TestSpan(t *testing.T) { }, events: []trace.Event{ { - Name: "Outbound compressed message", + Name: "Outbound message", Attributes: []attribute.KeyValue{ { Key: "sequence-number", @@ -1164,14 +1163,10 @@ func (s) TestSpan(t *testing.T) { Key: "message-size", Value: attribute.IntValue(10006), }, - { - Key: "message-size-compressed", - Value: attribute.IntValue(10006), - }, }, }, { - Name: "Inbound compressed message", + Name: "Inbound message", Attributes: []attribute.KeyValue{ { Key: "sequence-number", @@ -1181,22 +1176,18 @@ func (s) TestSpan(t *testing.T) { Key: "message-size", Value: attribute.IntValue(10006), }, - { - Key: "message-size-compressed", - Value: attribute.IntValue(10006), - }, }, }, }, }, { - name: "grpc.testing.TestService.UnaryCall", + name: "Sent.grpc.testing.TestService.UnaryCall", spanKind: oteltrace.SpanKindClient.String(), attributes: nil, events: nil, }, { - name: "grpc.testing.TestService.FullDuplexCall", + name: "Recv.grpc.testing.TestService.FullDuplexCall", spanKind: oteltrace.SpanKindServer.String(), attributes: []attribute.KeyValue{ { @@ -1219,7 +1210,7 @@ func (s) TestSpan(t *testing.T) { events: nil, }, { - name: "grpc.testing.TestService.FullDuplexCall", + name: "Sent.grpc.testing.TestService.FullDuplexCall", spanKind: oteltrace.SpanKindClient.String(), attributes: nil, events: nil, @@ -1300,7 +1291,7 @@ func (s) TestSpan_WithW3CContextPropagator(t *testing.T) { wantSpanInfos := []traceSpanInfo{ { - name: "grpc.testing.TestService.UnaryCall", + name: "Recv.grpc.testing.TestService.UnaryCall", spanKind: oteltrace.SpanKindServer.String(), attributes: []attribute.KeyValue{ { @@ -1322,7 +1313,7 @@ func (s) TestSpan_WithW3CContextPropagator(t *testing.T) { }, events: []trace.Event{ { - Name: "Inbound compressed message", + Name: "Inbound message", Attributes: []attribute.KeyValue{ { Key: "sequence-number", @@ -1332,14 +1323,10 @@ func (s) TestSpan_WithW3CContextPropagator(t *testing.T) { Key: "message-size", Value: attribute.IntValue(10006), }, - { - Key: "message-size-compressed", - Value: attribute.IntValue(10006), - }, }, }, { - Name: "Outbound compressed message", + Name: "Outbound message", Attributes: []attribute.KeyValue{ { Key: "sequence-number", @@ -1349,10 +1336,6 @@ func (s) TestSpan_WithW3CContextPropagator(t *testing.T) { Key: "message-size", Value: attribute.IntValue(10006), }, - { - Key: "message-size-compressed", - Value: attribute.IntValue(10006), - }, }, }, }, @@ -1380,7 +1363,7 @@ func (s) TestSpan_WithW3CContextPropagator(t *testing.T) { }, events: []trace.Event{ { - Name: "Outbound compressed message", + Name: "Outbound message", Attributes: []attribute.KeyValue{ { Key: "sequence-number", @@ -1390,14 +1373,10 @@ func (s) TestSpan_WithW3CContextPropagator(t *testing.T) { Key: "message-size", Value: attribute.IntValue(10006), }, - { - Key: "message-size-compressed", - Value: attribute.IntValue(10006), - }, }, }, { - Name: "Inbound compressed message", + Name: "Inbound message", Attributes: []attribute.KeyValue{ { Key: "sequence-number", @@ -1407,22 +1386,18 @@ func (s) TestSpan_WithW3CContextPropagator(t *testing.T) { Key: "message-size", Value: attribute.IntValue(10006), }, - { - Key: "message-size-compressed", - Value: attribute.IntValue(10006), - }, }, }, }, }, { - name: "grpc.testing.TestService.UnaryCall", + name: "Sent.grpc.testing.TestService.UnaryCall", spanKind: oteltrace.SpanKindClient.String(), attributes: nil, events: nil, }, { - name: "grpc.testing.TestService.FullDuplexCall", + name: "Recv.grpc.testing.TestService.FullDuplexCall", spanKind: oteltrace.SpanKindServer.String(), attributes: []attribute.KeyValue{ { @@ -1445,7 +1420,7 @@ func (s) TestSpan_WithW3CContextPropagator(t *testing.T) { events: nil, }, { - name: "grpc.testing.TestService.FullDuplexCall", + name: "Sent.grpc.testing.TestService.FullDuplexCall", spanKind: oteltrace.SpanKindClient.String(), attributes: nil, events: nil, @@ -1601,7 +1576,7 @@ func (s) TestTraceSpan_WithRetriesAndNameResolutionDelay(t *testing.T) { _, err := client.UnaryCall(ctx, &testpb.SimpleRequest{}) return err }, - spanName: "grpc.testing.TestService.UnaryCall", + spanName: "Sent.grpc.testing.TestService.UnaryCall", }, { name: "streaming", @@ -1645,7 +1620,7 @@ func (s) TestTraceSpan_WithRetriesAndNameResolutionDelay(t *testing.T) { } return nil }, - spanName: "grpc.testing.TestService.FullDuplexCall", + spanName: "Sent.grpc.testing.TestService.FullDuplexCall", }, } diff --git a/stats/opentelemetry/server_tracing.go b/stats/opentelemetry/server_tracing.go index f04d28c52ec3..261855193fee 100644 --- a/stats/opentelemetry/server_tracing.go +++ b/stats/opentelemetry/server_tracing.go @@ -33,7 +33,7 @@ import ( // If TextMapPropagator is not provided in the trace options, it returns context // as is. func (h *serverStatsHandler) traceTagRPC(ctx context.Context, ai *attemptInfo) (context.Context, *attemptInfo) { - mn := strings.Replace(ai.method, "/", ".", -1) + mn := "Recv." + strings.Replace(ai.method, "/", ".", -1) var span trace.Span tracer := h.options.TraceOptions.TracerProvider.Tracer(tracerName, trace.WithInstrumentationVersion(grpc.Version)) ctx = h.options.TraceOptions.TextMapPropagator.Extract(ctx, otelinternaltracing.NewIncomingCarrier(ctx)) diff --git a/stats/opentelemetry/trace.go b/stats/opentelemetry/trace.go index 4a49d8b03384..efafdd0756eb 100644 --- a/stats/opentelemetry/trace.go +++ b/stats/opentelemetry/trace.go @@ -57,18 +57,24 @@ func populateSpan(rs stats.RPCStats, ai *attemptInfo) { case *stats.InPayload: // message id - "must be calculated as two different counters starting // from one for sent messages and one for received messages." - span.AddEvent("Inbound compressed message", trace.WithAttributes( + attrs := []attribute.KeyValue{ attribute.Int64("sequence-number", int64(ai.countRecvMsg)), attribute.Int64("message-size", int64(rs.Length)), - attribute.Int64("message-size-compressed", int64(rs.CompressedLength)), - )) + } + if rs.CompressedLength != rs.Length { + attrs = append(attrs, attribute.Int64("message-size-compressed", int64(rs.CompressedLength))) + } + span.AddEvent("Inbound message", trace.WithAttributes(attrs...)) ai.countRecvMsg++ case *stats.OutPayload: - span.AddEvent("Outbound compressed message", trace.WithAttributes( + attrs := []attribute.KeyValue{ attribute.Int64("sequence-number", int64(ai.countSentMsg)), attribute.Int64("message-size", int64(rs.Length)), - attribute.Int64("message-size-compressed", int64(rs.CompressedLength)), - )) + } + if rs.CompressedLength != rs.Length { + attrs = append(attrs, attribute.Int64("message-size-compressed", int64(rs.CompressedLength))) + } + span.AddEvent("Outbound message", trace.WithAttributes(attrs...)) ai.countSentMsg++ case *stats.End: if rs.Error != nil {