Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stats/opentelemetry/client_tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
99 changes: 37 additions & 62 deletions stats/opentelemetry/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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{
{
Expand All @@ -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",
Expand All @@ -889,7 +896,7 @@ func (s) TestMetricsAndTracesOptionEnabled(t *testing.T) {
},
},
{
Name: "Outbound compressed message",
Name: "Outbound message",
Attributes: []attribute.KeyValue{
{
Key: "sequence-number",
Expand Down Expand Up @@ -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",
Expand All @@ -947,7 +954,7 @@ func (s) TestMetricsAndTracesOptionEnabled(t *testing.T) {
},
},
{
Name: "Inbound compressed message",
Name: "Inbound message",
Attributes: []attribute.KeyValue{
{
Key: "sequence-number",
Expand All @@ -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{
{
Expand All @@ -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,
Expand Down Expand Up @@ -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{
{
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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),
},
},
},
},
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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{
{
Expand All @@ -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,
Expand Down Expand Up @@ -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{
{
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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),
},
},
},
},
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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{
{
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1645,7 +1620,7 @@ func (s) TestTraceSpan_WithRetriesAndNameResolutionDelay(t *testing.T) {
}
return nil
},
spanName: "grpc.testing.TestService.FullDuplexCall",
spanName: "Sent.grpc.testing.TestService.FullDuplexCall",
},
}

Expand Down
2 changes: 1 addition & 1 deletion stats/opentelemetry/server_tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
18 changes: 12 additions & 6 deletions stats/opentelemetry/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down