If you consider the Gmaj which we land on as a 4th chord we are in the key of Dmaj. The lick has a great tension to it, thats why it functions well as a chordal run for the 4th chord in a major key. But you can use this chordal run for any maj7 chord as well. In this case for the Gmaj7(9).
here is a cool chordal neo-soul/gospel run I transcribed from the great Spanky Alford. A Great section to include in your instagram guitar chord melody playing or to end a song on a major chord. Have fun with the tutorial!