diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go index 6d8a82676ba..d1837ee0bf1 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go @@ -19,6 +19,7 @@ import ( "net" "strconv" "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -136,6 +137,12 @@ func TestInterceptors(t *testing.T) { }) t.Run("StreamClientSpans", func(t *testing.T) { + // StreamClientInterceptor ends the spans asynchronously. + // We need to wait for all spans before asserting them. + require.EventuallyWithT(t, func(c *assert.CollectT) { + assert.Len(c, clientStreamSR.Ended(), 3) + }, 5*time.Second, 100*time.Millisecond) + checkStreamClientSpans(t, clientStreamSR.Ended(), listener.Addr().String()) })