diff --git a/stats/opentelemetry/e2e_test.go b/stats/opentelemetry/e2e_test.go index 4e29f51aee62..e6629509fdcd 100644 --- a/stats/opentelemetry/e2e_test.go +++ b/stats/opentelemetry/e2e_test.go @@ -868,14 +868,6 @@ func (s) TestMetricsAndTracesOptionEnabled(t *testing.T) { Key: "FailFast", Value: attribute.BoolValue(false), }, - { - Key: "previous-rpc-attempts", - Value: attribute.IntValue(0), - }, - { - Key: "transparent-retry", - Value: attribute.BoolValue(false), - }, }, events: []trace.Event{ { @@ -990,14 +982,6 @@ func (s) TestMetricsAndTracesOptionEnabled(t *testing.T) { Key: "FailFast", Value: attribute.BoolValue(false), }, - { - Key: "previous-rpc-attempts", - Value: attribute.IntValue(0), - }, - { - Key: "transparent-retry", - Value: attribute.BoolValue(false), - }, }, events: nil, }, @@ -1092,14 +1076,6 @@ func (s) TestSpan(t *testing.T) { Key: "FailFast", Value: attribute.BoolValue(false), }, - { - Key: "previous-rpc-attempts", - Value: attribute.IntValue(0), - }, - { - Key: "transparent-retry", - Value: attribute.BoolValue(false), - }, }, events: []trace.Event{ { @@ -1198,14 +1174,6 @@ func (s) TestSpan(t *testing.T) { Key: "FailFast", Value: attribute.BoolValue(false), }, - { - Key: "previous-rpc-attempts", - Value: attribute.IntValue(0), - }, - { - Key: "transparent-retry", - Value: attribute.BoolValue(false), - }, }, events: nil, }, @@ -1302,14 +1270,6 @@ func (s) TestSpan_WithW3CContextPropagator(t *testing.T) { Key: "FailFast", Value: attribute.BoolValue(false), }, - { - Key: "previous-rpc-attempts", - Value: attribute.IntValue(0), - }, - { - Key: "transparent-retry", - Value: attribute.BoolValue(false), - }, }, events: []trace.Event{ { @@ -1408,14 +1368,6 @@ func (s) TestSpan_WithW3CContextPropagator(t *testing.T) { Key: "FailFast", Value: attribute.BoolValue(false), }, - { - Key: "previous-rpc-attempts", - Value: attribute.IntValue(0), - }, - { - Key: "transparent-retry", - Value: attribute.BoolValue(false), - }, }, events: nil, }, @@ -1766,8 +1718,6 @@ func (s) TestStreamingRPC_TraceSequenceNumbers(t *testing.T) { attributes: []attribute.KeyValue{ attribute.Bool("Client", false), attribute.Bool("FailFast", false), - attribute.Int("previous-rpc-attempts", 0), - attribute.Bool("transparent-retry", false), }, }, { diff --git a/stats/opentelemetry/trace.go b/stats/opentelemetry/trace.go index efafdd0756eb..680290bc3c8e 100644 --- a/stats/opentelemetry/trace.go +++ b/stats/opentelemetry/trace.go @@ -44,12 +44,17 @@ func populateSpan(rs stats.RPCStats, ai *attemptInfo) { // Note: Go always added Client and FailFast attributes even though they are not // defined by the OpenCensus gRPC spec. Thus, they are unimportant for // correctness. - span.SetAttributes( + attrs := []attribute.KeyValue{ attribute.Bool("Client", rs.Client), attribute.Bool("FailFast", rs.FailFast), - attribute.Int64("previous-rpc-attempts", int64(ai.previousRPCAttempts)), - attribute.Bool("transparent-retry", rs.IsTransparentRetryAttempt), - ) + } + if rs.Client { + attrs = append(attrs, + attribute.Int64("previous-rpc-attempts", int64(ai.previousRPCAttempts)), + attribute.Bool("transparent-retry", rs.IsTransparentRetryAttempt), + ) + } + span.SetAttributes(attrs...) // increment previous rpc attempts applicable for next attempt atomic.AddUint32(&ai.previousRPCAttempts, 1) case *stats.PickerUpdated: